Here's my code,
Line 1 - $imagename = $_FILES['file']['name'];
Line 2 - $source = $_FILES['file']['tmp_name'];
Line 3 - $target = "images/".$imagename;
Line 4 - move_uploaded_file($source, $target);
Line 5 -
Line 6 - $imagepath = $imagename;
Line 7 - $save = "images/" . $imagepath; //This is the new file you saving
Line 8 - $file = "images/" . $imagepath; //This is the original file
Line 9 -
Line 10 - list($width, $height) = getimagesize($file);
Line 11 -
Line 12 - $tn = imagecreatetruecolor($width, $height) ;
Line 13 - $image = imagecreatefromjpeg($file);
imagecopyresampled($tn, $image, 0, 0, 0, 0, $width, $height, $width, $height) ;
imagejpeg($tn, $save, 80) ;
$save = "thumb_/" . $imagepath; //This is the new file you saving
$file = "images/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 130;
$diff = $width / $modwidth;
$modheight = 185;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 80) ;
I have error here.
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 13056 bytes) in C:\xampp\htdocs\MagicLine\admin\cleo\cleo.php on line 13
You need to raise your memory limit in your php.ini file. The 128MB limit was exhausted when it tried to allocate 13KB more for one of the operations.
http://php.net/manual/en/ini.core.php#ini.memory-limit
You can set this in run time by using ini_set().
Note: It is typically unusual for a PHP script to utilize 128MB of memory on its own, but it depends on what you are doing. I don't have experience with these image functions, so you would have to decide if this is normal usage or if you have a memory leak somewhere in your script.
Add this code to the beginning of your script:
$old = ini_get('memory_limit');
Then choose from these three options:
ini_set('memory_limit', '128M');
ini_set('memory_limit', '256M');
ini_set('memory_limit', '512M');
At the end of your script (BEFORE exit;
) add:
ini_set('memory_limit', $old);
Now your problem should be solved.