Web Analytics Made Easy -
StatCounter file upload script error - CodingForum

Announcement

Collapse
No announcement yet.

file upload script error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • file upload script error

    Hi i have the following code which will upload a file onto the server however i get the following errors.

    Warning: move_uploaded_file(stuff/Correct VT1.xls) [function.move-uploaded-file]: failed to open stream: Permission denied in /var/www/html/upload.php on line 52

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpblvC1H' to 'stuff/Correct VT1.xls' in /var/www/html/upload.php on line 52
    Somthing is wrong with uploading a file.


    my code is as follows:-

    PHP Code:
    <?php 

    $site_name 
    $_SERVER['HTTP_HOST']; 
    $url_dir "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']); 
    $url_this =  "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; 

    $upload_dir "stuff/"
    $upload_url $url_dir."/stuff/"
    $message =""

    //create upload_files directory if not exist 
    //If it does not work, create on your own and change permission. 
    if (!is_dir("stuff")) { 
      die (
    "stuff directory doesn't exist"); 


    if (
    $_FILES['userfile']) { 
      
    $message do_upload($upload_dir$upload_url); 

    else { 
      
    $message "Invalid File Specified."


    print 
    $message

    function 
    do_upload($upload_dir$upload_url) { 

      
    $temp_name $_FILES['userfile']['tmp_name']; 
      
    $file_name $_FILES['userfile']['name']; 
      
    $file_type $_FILES['userfile']['type']; 
      
    $file_size $_FILES['userfile']['size']; 
      
    $result    $_FILES['userfile']['error']; 
      
    $file_url  $upload_url.$file_name
      
    $file_path $upload_dir.$file_name

      
    //File Name Check 
       
    if ( $file_name =="") { 
          
    $message "Invalid File Name Specified"
          return 
    $message
       } 
       
    //File Size Check 
       
    else if ( $file_size 5000000000000000) { 
           
    $message "The file size is over 500K."
           return 
    $message
       } 
       
    //File Type Check 
       
    else if ( $file_type == ".exe" ) { 
           
    $message "Sorry, You cannot upload any exe  file"
           return 
    $message
       } 

       
    $result  =  move_uploaded_file($temp_name$file_path); 
       
    $message = ($result)?"File url <a href=$file_url.>$file_url</a>" 
                
    "Something is wrong with uploading a file."

       return 
    $message


    ?> 
    <form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post"> 
     Upload File<input type="file" id="userfile" name="userfile"> 
     <input type="submit" name="upload" value="Upload"> 
    </form>
    any help would be great cheers.

  • #2
    Quite a common error actually, I had great difficulty trying to solve this easy problem, but got there in the end.

    Obviously, its a unix server the site is hosted on - I assume you have FTP Access, meaning you can CHMod a file.

    Warning: move_uploaded_file(stuff/Correct VT1.xls) [function.move-uploaded-file]: failed to open stream: Permission denied in /var/www/html/upload.php on line 52

    Permission denied means the file itself don't have permission to move the new file - so you need to CHMod it. I've always chmodded to 0777, but I believe 0775 or 0755 will work. You only need to CHMod upload.php.

    If this don't work, it could mean you either need to chmod the new destination, wrong CHMod again or it may be something else.

    Good luck

    Comment


    • #3
      thanks for that works now.

      Comment

      Working...
      X