I am building a reviews site and having issues with my image uploads processing. I have set up my php.ini to allow for a max_file_uploadsize of 10M and a post_max_size of 60M but I am limiting my file upload size to 6MB. I am using the smart_resize_image function to resize my images. I am allowing a max of 5 images to be uploaded and looping through the $_FILES array with a foreach loop. Here is my image processing code:
$allowed = array('image/pjpeg', 'image/jpeg', 'image/jpg', 'image/JPG', 'image/PNG', 'image/png');
$i = 1;
foreach($_FILES as $image) {
if (file_exists($image['tmp_name'])) {
if (in_array($image['type'], $allowed)) {
if($image['size'] < 6291456) {
include_once('/inc/smart_resize_image.function.php');
$movedL = '/public_html/ureview/images/restaurants/'.$pid.'/'.$sid.'-'.$i.'.jpg';
smart_resize_image($image['tmp_name'], null, 800, 500, true,$movedL, true,false,100);
$i++;
}else{
echo'Image #'.$i.' file size limit of 5MB!';
exit();
}
}else{
echo'Image #'.$i.' file type not allowed!';
exit();
}
}
}
The error I am getting is:
Allowed memory size of 33554432 bytes exhausted (tried to allocate 12288 bytes) in /inc/smart_resize_image.function.php
I think what the issue is that the smart_resize_image function is unlinking after processing but not freeing up memory. I know there are multiple sites that process image uploads so it is possible but I can not figure out what I need to change in my code.
EDIT: I am looking to see if there are inefficiencies in my code above that would cause the error to happen.