I am trying to create a neat little system that will allow me to upload an image and save it plus a thumbnail. It works fine until I get to an image that's over 100kb. When I try to upload an image that's 101kb, I get this message:
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 8496 bytes) in [path name removed] on line 27
Here is the code:
<?php
if (@$_POST['submit']) {
if (is_uploaded_file($_FILES['infile']['tmp_name'])) {
$filename = $_FILES['infile']['name'];
$sizes = getimagesize($_FILES['infile']['tmp_name']);
$width = $sizes[0];
$height = $sizes[1];
$path = '[path name removed]';
if (move_uploaded_file($_FILES['infile']['tmp_name'], $path.$filename)) {
@chmod($filename,0666);
if ($width > 75) {
$newwidth = 75;
$proportion = 75/$width;
$newheight = round($height*$proportion,0);
} elseif ($height > 75) {
$newheight = 75;
$proportion = 75/height;
$newwidth = round($width*$proportion,0);
}
if (@$newheight) {
$thumb = "th_".$filename;
error_reporting (E_ALL);
$abc = imagecreatefromjpeg($filename);
$def = imagecreate($newwidth, $newheight);
imagecopyresized($def, $abc, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($def, $thumb, 95);
imagedestroy($abc);
imagedestroy($def);
@chmod($thumb,0666);
print "
original: ($width x $height)<hr><img src=\"$filename\"><br><br><br>new:($newwidth x $newheight)<hr><img src=\"$thumb\"></BODY></HTML>";
}
} else {
$m="could not copy image";
}
} else {
$m = "file could not be uploaded";
}
}
?>
The form is pretty straight-forward and looks like this:
<form action="<?= $PHP_SELF; ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="80000000">
image: <input type="file" name="infile"><br>
<input type="submit" value="submit" name="submit">
</form>
Can anyone tell me what I'm missing? My server allows uploads of up to 2MB.
Thanks.