SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict jamesbond's Avatar
    Join Date
    Feb 2001
    Location
    The Netherlands
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I have been using the following upload form method for a while, but now all of a sudden it doesn't work correctly anymore (due to serverupgrades maybe?)
    It does upload the file, but the filename is not correct anymore.

    Below I show a simplified situation.
    If I use the first upload box (file1), the filename on the server will be named file1.jpg

    If I use the second upload box (file2) (which is on the same page) the filename on the server doesn't get the name file2.jpg anymore, but instead is named file1.jpg!

    I didn't have this problem until last week...anyone know what causes this and how to fix it?
    I am careful using arrays since I only want it to upload 1 file at a time, if one uses the 2nd upload box, the only file uploaded shoud be named file2.jpg and so on.

    I just can't figure out why it doesn't work properly anymore, since I didn't touch any of the files.


    upload.php:


    <!-- -------- FORM 1 ------------------------- -->
    <FORM ENCTYPE="multipart/form-data" ACTION="
    <? echo "$PHP_SELF"; ?>" method="POST">

    <br>
    <input type="hidden" name="username" value="file1">
    <input type="hidden" name="submitted" value="true" >
    <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="
    <? echo"$max_upload" ; ?>
    ">
    Upload: <INPUT NAME="userfile" TYPE="file">
    <INPUT TYPE="submit" VALUE="Upload">
    </FORM>


    <!-- -------- FORM 2 ------------------------- -->
    <FORM ENCTYPE="multipart/form-data" ACTION="
    <? echo "$PHP_SELF"; ?>" method="POST">

    <br>
    <input type="hidden" name="username" value="file2">
    <input type="hidden" name="submitted" value="true" >
    <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="
    <? echo"$max_upload" ; ?>
    ">
    Upload: <INPUT NAME="userfile" TYPE="file">
    <INPUT TYPE="submit" VALUE="Upload">
    </FORM>


    The upload.inc class used uploading the file :

    ?

    //----------------------------------------
    //-----Start upload.inc-------------
    //----------------------------------------

    //$userfile_name is the name of the file when it was on the client
    $clients_file_name = $userfile_name;

    //$userfile is the full path of the temporary server file. The name is
    // random and exists for the duration of the script only
    $temp_file_name= basename($userfile);

    // extract file extension of uploaded file
    $arr_basename=explode(".",$clients_file_name);
    $file_type=$arr_basename[1];


    if (($file_type=="jpg") || ($file_type=="jpeg") || ($file_type=="gif")){
    //allow upload only for txt and gif types

    $new_file_name=$username.".".$file_type;

    $temp_full_path=$userfile;
    $final_full_path=$final_location.$new_file_name;

    if (!copy($temp_full_path, $final_full_path)) {
    $error_msg = "error occured $file...
    \n";

    } // end if



    } // end file type check
    else { $error_msg= "Upload failed - only jpg and gif are allowed<br> " ; }
    //----------------------------------------
    //-----End upload.inc-------------
    //----------------------------------------

    ?>

  2. #2
    SitePoint Addict jamesbond's Avatar
    Join Date
    Feb 2001
    Location
    The Netherlands
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fixed it!


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
  •