Hy, I have a page where a user can upload an image (one at a time, the second upload overwrites the first one).
When someone chooses an image which is more than 5 MB, the script will upload the image but it will then run another script that will resize the image to make it smaller.
So, i get the image size, and set the maximum size like so:
$size = $_FILES["userImage"]["size"]
$maxSize = 5000000 //this should be 5 MB, right?
then, I move the image to a folder with this line
move_uploaded_file( $tmpName, "../user_img/".$sessionId."/".$sessionId."_img.".$type);
and in the end, I want to resize the image if it is above 5 MB
if($size > $maxSize){
include('resizeImage2.php');
//indicate which file to resize (can be any type jpg/png/gif/etc...)
$file = "../user_img/".$sessionId."/".$sessionId."_img.".$type;
//indicate the path and name for the new resized file
$resizedFile = $file;
//call the function (when passing path to pic)
//smart_resize_image($file, null, 1200, 0, true, $resizedFile, true, false, 100 );
//call the function (when passing pic as string)
smart_resize_image(null , file_get_contents($file), 1200 , 0 , true , $resizedFile , true , false ,100 );
}
the resizeImage2.php is something I found on the internet at this address
and the problem occurs when I try to upload an image from my PC that is 7MB, and 10004 x 10967 in resolution. I get an error
Allowed memory size of 62914560 bytes exhausted (tried to allocate 40016 bytes)
I know i can change the memory limit in php.ini, but i was wondering if there is another way to make this work? Are any of my scripts badly written?
Thanks in advance!
Try this put it at header on page-
<?php
ini_set('memory_limit','16M');
?>
You can increase this uploaded files limit in your php.ini
file, by adding or updating a line similar to the following:
memory_limit = 128M
There are two tricks to increase the max upload size in php
Increasing file upload size by .htaccess
php_value upload_max_filesize 10M
Increasing file upload size by php.ini
files
upload_max_filesize = 10M