SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image upload not working

    Works locally but not live.
    My file location is piercemcgeough.co.uk/com533/wolfhatmartialarts/admin/addproduct.php
    And where i want the image to go is piercemcgeough.co.uk/com533/wolfhatmartialarts/images/products/

    Warning i get live is:
    Warning: move_uploaded_file(../images/products/wolf - Copy.jpg): failed to open stream:
    Permission denied in /usr/local/pem/vhosts/171950/webspace/httpdocs/piercemcgeough.co.uk/com533/wolfhatmartialarts/admin/addproduct.php on line 46

    Warning: move_uploaded_file(): Unable to move '/usr/local/pem/vhosts/171950/tmp/phpOWqMkC' to '../images/products/wolf - Copy.jpg' in /usr/local/pem/vhosts/171950/webspace/httpdocs/piercemcgeough.co.uk/com533/wolfhatmartialarts/admin/addproduct.php on line 46

    And this is my code.
    PHP Code:
    if($_POST['add']){
            
    $target "../images/products/";
            
    $target $target basename($_FILES['photo']['name']); 
            
            
    $pname $_FILES['photo']['name'];
            
    $ptemp $_FILES['photo']['tmp_name'];
            
    $ptype $_FILES['photo']['type'];
            
    $psize $_FILES['photo']['size'];

            if(
    move_uploaded_file($_FILES['photo']['tmp_name'], $target)){ 
                
    redirect_to('index.html');
            } 
    Really confused and stuck

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,410
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    1/ Echo out your variables to see what they contain.

    2/ This looks like your problem "Unable to move '/usr/local/pem/vhosts/171950/tmp/phpOWqMkC" as the file does not have an extension and it is to much of a coincidence to be a random name starting with php.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Variables are as following

    Target: ../images/products/sm-wolf.jpg
    pname: sm-wolf.jpg
    ptemp: /usr/local/pem/vhosts/171950/tmp/phpWKgPrd
    ptype: image/jpeg
    psize: 11389

    Also i tried the w3schools uploading and it didnt work. Worked locally but not live
    http://www.w3schools.com/php/php_file_upload.asp

  4. #4
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,410
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    As I say this looks wrong "ptemp: /usr/local/pem/vhosts/171950/tmp/phpWKgPrd" Again your tempory file is starting with php.

    Have you changed the permissions on the ../images/products/ folder to either 777 or 755 ?

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry im a bit of a noob with file uploads. Just have the code from above in the addproduct.php file and want it to locate the image up a level and back into images/products.

    No idea about permissions. Im using blacknight hosting

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually im using htaccess to change .php to .html with this
    RewriteEngine on
    RewriteRule ^(.*)\.html$ $1.php

  7. #7
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,410
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    Do you know if you are on a Windows or Linux server?

  8. #8
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well im using apache so im assuming its linux.
    Cant figure this out. Head is wrecked

  9. #9
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,410
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    As you say probably Linux

    It looks like your problem is a permission one as you have the error "Permission denied ".

    I am not sure if moving a file needs the folder permissions changing but I would try changing the permission of products to 777

    In your FTP program when you look at the folder it probably has a permission of 644 try changing that to 777 - right click on the foldername - change permission. You may be able to set ti to 757 or 755 if this works.

  10. #10
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should i do that to images folder and products folder within it?

  11. #11
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Everything working now. thank you ever so much


Tags for this Thread

Bookmarks

Posting Permissions

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