Page 1 of 1

File upload

Posted: Tue Mar 17, 2009 11:07 am
by lubber123
I am having a problem with some file upload code. The code works fine from my local system but when I upload it to my host I get errors. Below is the code (the upload code is bolded) followed by the errors - with the redirect commented out. I think I may have a permission problem from my host but I want to make sure I can't solve this with code before I check with them. If anyone can help I would appreciate it.

Code: Select all

 
 
... else{
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
                    
    if (file_exists("../images/" . $_FILES["file"]["name"])){
        $error_msg = "The file already exists.";
        header('LOCATION: uploadimage.php?err=' . $error_msg . '&action=create');
        exit;
    }else{
    
      [b]move_uploaded_file($_FILES["file"]["tmp_name"], "../images/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "../images/" . $_FILES["file"]["name"];[/b]
        //$error_msg = "Thank you. The file was uploaded.  Upload another?";
        //header('LOCATION: uploadimage.php?err=' . $error_msg . '&action=create');
        //exit;
    }
  }
}else
{
    $error_msg = "This is an invalid file.  Please choose another one";
        header('LOCATION: uploadimage.php?err=' . $error_msg . '&action=create');
exit;
}
 

Error:

Upload: back.jpg
Type: image/pjpeg
Size: 8.55859375 Kb
Stored in: /tmp/phpmreoqCUpload: back.jpg
Type: image/pjpeg
Size: 8.55859375 Kb
Stored in: /tmp/phpmreoqCUpload: back.jpg
Type: image/pjpeg
Size: 8.55859375 Kb
Temp file: /tmp/phpmreoqC

Warning: move_uploaded_file(../images/back.jpg): failed to open stream: Permission denied in /home/lfchur5/public_html/staff/uploadimage.php on line 94

Warning: move_uploaded_file(): Unable to move '/tmp/phpmreoqC' to '../images/back.jpg' in /home/lfchur5/public_html/staff/uploadimage.php on line 94
Stored in: ../images/back.jpg

Re: File upload

Posted: Tue Mar 17, 2009 11:34 am
by a.heresey
Sound's like permission problem with your host.

PHP manual:
If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.

Re: File upload

Posted: Wed Mar 18, 2009 6:58 am
by lubber123
Okay thanks. I will try to sort it with them then. Thanks for your time.