dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: fileupload fails

  1. #1
    Join Date
    May 2009
    Posts
    17

    fileupload fails

    i am trying to upload a file to the server, i found basic tutorials to do so, but moveuploaded file fails
    i tried to debug the script and it appears that all the variables are correct, the file path is valid on the server, and the tmpfile path and name appear correct, this is the php i am using
    PHP Code:
    <?php
    foreach($_POST as $key => $value){


      if(
    $value != ""){
        
    $message .= $key" --------- " $value"\n" ;
      
        echo   
    $key " ----- " $value"<br>";
       }else{
        
    $error true;
        
      }
    }
    foreach(
    $_FILES as $myfile => $xxx){
    foreach(
    $xxx as $uploadedfile => $name){
    echo 
    $uploadedfile " ----- " $name "<br>";
    }
     }
    $target_path getcwd(). "/upload/";

    echo 
    $_FILES["uploadedfile"]["tmp_name"]."<br>";
    echo 
    exec('whoami');
    chmod($_FILES["uploadedfile"]["name"],0777);
    echo 
    substr(sprintf('%o'fileperms($_FILES["uploadedfile"]["tmp_name"])), -4)."<br>";


    // ulink($_FILES["uploadedfile"]["tmp_name"]);

    echo $_FILES["uploadedfile"]["name"]."<br>";

    $target_path $target_path basename$_FILES['uploadedfile']['name']); 
      
    //    copy($_FILES["uploadedfile"]["tmp_name"], $target_path . $_FILES["uploadedfile"]["name"]);
    echo $target_path."<br>";
    if(
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo 
    "The file ".  basename$_FILES['uploadedfile']['name']). 
       
    " has been uploaded";
    } else{
        echo 
    "There was an error uploading the file, please try again!";
    }
    ?>
    i have 2 file inputs in a htm page and get a return like
    MAX_FILE_SIZE ----- 1000000
    name ----- bin_file.txt
    type ----- text/plain
    tmp_name ----- /tmp/phpMtU95N
    error ----- 0
    size ----- 4135
    name -----
    type -----
    tmp_name -----
    error ----- 4
    size ----- 0
    /tmp/phpMtU95N
    apache0600
    bin_file.txt
    /home/***/castagna/upload/bin_file.txt
    There was an error uploading the file, please try again!
    only 1 file input filled

    i do not find the tmpfile in the server tmp folder
    the chmod does not appear to change the permissions, maybe apache is not authorised to do so?

    if found this in a thread here, courtsey //./
    <?php echo phpinfo(); ?>

    which returns
    way too much to post here,
    but i can post any parts that may help

  2. #2
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    I would suggest you look at the sticky at the top of the forum that covers this upload to the server and it is something that you can easily build on.

    Your upload could be failing for a number of reasons, it could be a wrong path your trying to get or set or it could be that the file is too big for the max upload.

  3. #3
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,774

  4. #4
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    Looking at the script, your attempting to chmod a file reference that has not yet been moved...

    I suggest that you follow the example of file uploads as written by Bokeh here. Which is a very good tutorial that you can build upon.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles