I'm testing a file upload script on localhost with apache 1.3.27 on windows xp.

This is my form:

<form enctype="multipart/form-data" action="upload.php" method="post">
file: <input type="file" name="userfile" size="30"><br>
<input type="submit" value="Send">
</form>

This is my script:

$tempname = $FILES['userfile'];
if( is_uploaded_file( $tempname ) )
{
if( move_uploaded_file( $
FILES['userfile']['tmp_name'],$SERVER['DOCUMENT_ROOT'].'/docs/uploads/'.$FILES['userfile']['name'] ) )
echo 'SUCCESS';

}

But It doesn't seem to upload the file. Well, first of all, where should the uploaded file be located? 😃
Is my script ok?

Please help,

Thanks!!

    file upload dir is set in the php.ini. Use print_r($_FILES['userfile']); for debugging help

      from the manual .....

      <HTML>
      <TITLE>
      File upload
      </title>
      <body>

      <B>File upload</b>

      <form enctype="multipart/form-data" action="<?PHP echo $PHP_SELF ?>" method="post">

      <!-- "MAX_FILE_SIZE" determines the biggest size an uploaded file can occupy -->

      <input type="hidden" name="MAX_FILE_SIZE" value="500000">
      Send this file:
      <input name="userfile" type="file">
      <input type="submit" name="submit" value="Send File">
      </form>

      </body>

      <?PHP

      /*

      $userfile - The temporary filename in which the uploaded file was stored on the server machine.

      $userfile_name - The original name or path of the file on the sender's system.

      $userfile_size - The size of the uploaded file in bytes.

      $userfile_type - The mime type of the file if the browser provided this information. An example would be "image/gif".

      */

      // copy to this directory

      $dir="./bor/";

      // copy the file to the server

      if (isset($submit)){

      copy($userfile,$dir.$userfile_name);

      if (!is_uploaded_file ($userfile)){

      echo "
      <b>$userfile_name</b> couldn't be copied !!";
      }
      }

      // check whether it has been uploaded

      if (is_uploaded_file ($userfile)){

      echo "
      <b>$userfile_name</b> copied succesfully !!";

      }

      ?>

      </html>

      reg
      kevin

        Thanks for the tip!
        I found out what the problem was:

        $tempname = $FILES['userfile']['tmp_name']; // CHANGE HERE
        if( is_uploaded_file( $tempname ) )
        {
        if( move_uploaded_file( $
        FILES['userfile']['tmp_name'],$SERVER['DOCUMENT_ROOT'].'/docs/uploads/'.$FILES['userfile']['name'] ) )
        echo 'SUCCESS';
        }

        And I also changed the upload dir in php.ini.

        Works great now!
        🙂

          Write a Reply...