Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts

    Need help debugging a file upload script

    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:

    PHP Code:
    $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$tempImg0000$finalWidth$finalHeight$imgWidth$imgHeight);

    // MySQL stuff here

    imagejpeg($tempColorFILEROOT."/images/ads/$adID.jpg"100);
    imagedestroy($tempImg);
    imagedestroy($tempColor); 
    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?
    Last edited by Keleth; 01-31-2012 at 05:15 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •