Page 1 of 1

move upload confusion

Posted: Thu Dec 17, 2009 9:16 am
by jodeti
Hello,
It may be silly. Is that possible. Trying to upload one file(image file) from the form to a directory with different name.

Code: Select all

$CurrentPath="./upload";
$_POST["ActionIfFileExistsOnUpload"]="Make unique";
if(isset($_FILES["FileToUpload"])&&$_FILES["FileToUpload"]["name"]!="")
    {
        $NewName = $_FILES["FileToUpload"]["name"];
if(file_exists("$CurrentPath/{$_FILES["FileToUpload"]"name"]}")&&$_POST["ActionIfFileExistsOnUpload"]=="Make unique")/*ignore that one it's just try to be a unique*/
        {
        $NewName = md5(uniqid(rand(0, 1000),1))."_".$_FILES["FileToUpload"]["name"];
        $thumb = md5(uniqid(rand(0, 1000),1))."thumb_".$_FILES["FileToUpload"]["name"];
            }  
    move_uploaded_file($_FILES["FileToUpload"]["tmp_name"], "$CurrentPath/$NewName");
    $thumb = "thumb_".$_FILES["FileToUpload"]["name"];/*try to rename*/
    move_uploaded_file($_FILES["FileToUpload"]["tmp_name"], "$CurrentPath/$thumb"); /possible????????/
      }
When try to upload by removing the "below two line" it work usual but when i try to add this two line to upload that file with different name. One is the $_FILES["FileToUpload"]["name"] and the other is the $thumb.

Code: Select all

$thumb = "thumb_".$_FILES["FileToUpload"]["name"];
move_uploaded_file($_FILES["FileToUpload"]["tmp_name"], "$CurrentPath/$thumb");
Adding these two line doesn't effect the script. The script create filename with the first one($NewName).
Is this a overwriting issue or it doesn't work because it move_uploaded_file(I mean try to cut from php temporary to the destination.) That's why those two line has no effect in the script??????????

Any suggestion?

thank you ALL.

Re: move upload confusion

Posted: Thu Dec 17, 2009 10:20 am
by AbraCadaver
In line 11 above you have already "moved" the uploaded file from 'tmp_name', so it is no longer there and you can't move it again. Try this on line 13 instead:

Code: Select all

copy("$CurrentPath/$NewName", "$CurrentPath/$thumb");

Re: move upload confusion

Posted: Fri Dec 18, 2009 2:08 am
by jodeti
It works what i wanted. thank you.