Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP Problem

  • 18-03-2007 08: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, Registered Users 2 Posts: 1,991 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 7,742 ✭✭✭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