I've two idedentical scripts, running on two different servers.
Server I = PHP Version 5.0.4, GD 2.0.28 compatible, MAX UPLOAD = 100mb, max_execution_time 30
Server II =PHP Version 4.4.2, GD 2.0 or higher, MAX UPLOAD = 20mb, max_execution_time 50000
Upoading an small image, saving it, creating a thumbnail and saving that, works on both servers.
However, it will work for a 4mb+ file on Server I, while on Server II it will upload the file ok(all 4mb), but knock out and save a dreaded black thumbnail. I have excluded filename charaters as an issue, and permission problems because the script otherwise works fine on server II.
Code is derived from php.net examples, and some parts I found floating around here.
Is it just that Server II will not handle a large upload? Or can it be made to work?
Code: Select all
$currentDir = getcwd();
$filetype = $_FILES['userfile']['type'];
$filesize = $_FILES['userfile']['size'];
// Prepend the file with the md5 to make it unique
$unique_id = md5(uniqid(time()));
$file = $_FILES['userfile']['name'];
$filename = $unique_id.'_'.$file;
// Upload the File
$uploaddir = $currentDir."/images/highres/";
$uploadfile = $uploaddir . basename($filename);
// Check it's up
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
$uploadCheck = 'Yes';
} else {
$uploadCheck = 'No';
}
chmod($uploadfile, 0666);
// Copy to thumbs folder
$oldfile = $currentDir."/images/highres/".$filename;
$newfile = $currentDir."/images/lowres/".substr($filename, -20);
$newfileToDB = substr($filename, -20);
if (!copy($oldfile, $newfile)) {
echo "failed to copy $file...\n";
}
// Resize
$width = 240;
$height = 180;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($newfile);
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($newfile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, $newfile, 100);
chmod($newfile, 0666);
//