View Full Version : Resolved Need help debugging a file upload script

01-31-2012, 03:35 PM
I'm using a file upload script I've used many times before, this time on a new server, and I can't figure out what's stopping it from working; I'm hoping someone can help me debug it for my current and future knowledge.

The script is as follows:

$maxWidth = $zones[$zone]['width'];
$maxHeight = $zones[$zone]['height'];

list($imgWidth, $imgHeight, $imgType) = getimagesize($_FILES['adImg']['tmp_name']);
if (image_type_to_mime_type($imgType) == 'image/jpeg' || image_type_to_mime_type($imgType) == 'image/pjpeg') $tempImg = imagecreatefromjpeg($_FILES['adImg']['tmp_name']);
elseif (image_type_to_mime_type($imgType) == 'image/gif') $tempImg = imagecreatefromgif($_FILES['adImg']['tmp_name']);
elseif (image_type_to_mime_type($imgType) == 'image/png') $tempImg = imagecreatefrompng($_FILES['adImg']['tmp_name']);

$xRatio = $maxWidth / $imgWidth;
$yRatio = $maxHeight / $imgHeight;

if ($imgWidth <= $maxWidth && $imgHeight <= $maxHeight) {
$finalWidth = $imgWidth;
$finalHeight = $imgHeight;
} elseif (($xRatio * $imgHeight) < $maxHeight) {
$finalWidth = $maxWidth;
$finalHeight = ceil($xRatio * $imgHeight);
} else {
$finalWidth = ceil($yRatio * $imgWidth);
$finalHeight = $maxHeight;

$tempColor = imagecreatetruecolor($finalWidth, $finalHeight);
imagecopyresampled($tempColor, $tempImg, 0, 0, 0, 0, $finalWidth, $finalHeight, $imgWidth, $imgHeight);

// MySQL stuff here

imagejpeg($tempColor, FILEROOT."/images/ads/$adID.jpg", 100);

If I add in a jpg content type header and ech out imagejpeg, the image shows up, so I know its processing the image correctly. I just can't seem to get the file to save anywhere. I've tried changing it to another folder, changing the save location to just '/', etc, but nothing seems to work. I've checked the folder permissions (changed to 775 just to see if group was required), and checked phpinfo for any upload related settings, and the ones I know of seem to be set.

Any thoughts to what's wrong or what I can check?

01-31-2012, 05:15 PM
So of course, though I had checked the file permissions, it seems they never took. I talked to my boss about the same issue, he tried setting file permissions (which seemed to work on my end), tried the code, and it worked just fine. Go figure.

So the issue was just file permissions, and maybe FileZilla...