Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP Problem

Options
  • 18-03-2007 8:10pm
    #1
    Closed Accounts Posts: 10


    Hi,

    I'm having a bit of trouble with my PHP image upload script... anyone got any ideas? I think its something to do with the directory permissions but i'm a bit of a PHP n00b tbh...

    Here's my PHP:
    [PHP]
    $image = $_FILES[image][name];

    $size = 100; // the thumbnail height
    $filedir = 'upload/'; // the directory for the original image
    $thumbdir = 'upload/'; // the directory for the thumbnail image
    $prefix = 'tn_'; // the prefix to be added to the original name
    $maxfile = '20000000';
    $mode = '0666';
    $userfile_name = $_FILES[image][name];
    $userfile_name = str_replace(" ","-",$userfile_name);
    $userfile_tmp = $_FILES[image][tmp_name];
    $userfile_size = $_FILES[image][size];
    $userfile_type = $_FILES[image][type];

    if ($image!="")
    {
    $prod_img = $filedir.$userfile_name;
    $prod_img_thumb = $thumbdir.$prefix.$userfile_name;
    move_uploaded_file($userfile_tmp, $prod_img);
    chmod ($prod_img, octdec($mode));
    $sizes = getimagesize($prod_img);
    $aspect_ratio = $sizes[1]/$sizes[0];
    if ($sizes[1] <= $size)
    {
    $new_width = $sizes[0];
    $new_height = $sizes[1];
    }else{
    $new_height = $size;
    $new_width = abs($new_height/$aspect_ratio);
    }
    $destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image');
    $srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image');
    ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing');
    ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving');
    imagedestroy($destimg);
    $image = "Image Uploaded!";
    }
    [/PHP]

    And here is the errors i get....
    Warning: move_uploaded_file(upload/myimage.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/username/domains/mydomain.ie/public_html/test/uploader/imageUpload.php on line 31
    
    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpXHhsVv' to 'upload/myimage.jpg' in /home/username/domains/mydomain.ie/public_html/test/uploader/imageUpload.php on line 31
    
    Warning: chmod() [function.chmod]: No such file or directory in /home/username/domains/mydomain.ie/public_html/test/uploader/imageUpload.php on line 32
    
    Warning: getimagesize(upload/myimage.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/username/domains/mydomain.ie/public_html/test/uploader/imageUpload.php on line 33
    
    Warning: Division by zero in /home/username/domains/mydomain.ie/public_html/test/uploader/imageUpload.php on line 34
    
    Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/username/domains/mydomain.ie/public_html/test/uploader/imageUpload.php on line 43
    Problem In Creating image
    


Comments

  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    Permission denied in /home/username/domains/mydomain.ie/public_html/test/uploader/imageUpload.php on line 31
    I would say its to do with your permissions! But don't quote me!


  • Registered Users Posts: 467 ✭✭nikimere


    post retracted... i was wrong :) please feel free to delete this post :p


  • Closed Accounts Posts: 10 Mr.Orange


    Ok, but what should i be asking my hosting provider to do? What kind of permissions need to be changed?


  • Registered Users Posts: 7,739 ✭✭✭mneylon


    You probably want to make the directory where the images are being uploaded / manipulated writeable by the server

    If the directories are "owned" by your user you should be able to make the necessary changes


Advertisement