Reputation:
I am working on an upload page. I need to send the same file upload (from the user) to various different paths for display.
The following work to upload the file to a single path:
if(move_uploaded_file($fileTmpLoc, $filepath)){
//Do something
}
Using move_uploaded_file I have tried the following but did not work:
if(move_uploaded_file($fileTmpLoc, ($filepath, $anotherfilepath))){
//Do something
}
if(move_uploaded_file($fileTmpLoc, $filepath)){
//Do something
}
if(move_uploaded_file($fileTmpLoc, $anotherfilepath)){
//Do something
}
if(move_uploaded_file($fileTmpLoc, $filepath) && (move_uploaded_file($fileTmpLoc, $anotherfilepath)){
//Do something
}
Any suggestions would be helpful.
Upvotes: 0
Views: 1184
Reputation: 81
move_uploaded_file will move the file, and not copy it -- which means it'll work only once.
i think you should user copy function after first copy like:
if(move_uploaded_file($fileTmpLoc,$filepath)){
//Do something
}
if(copy($filepath, $filepath)){
//Do something
}
if(copy($filepath, $anotherfilepath)){
//Do something
}
Upvotes: 0
Reputation: 346
Try the following:
if(move_uploaded_file($tmp, $new_dest)){
//moved to destination, now copy
copy($new_dest, $another_new_dest);
}
if you need it to copy to more then one other
if(move_uploaded_file($tmp, $new_dest)){
//moved to destination, now copy
copy($new_dest, $another_new_dest);
copy($new_dest, $yet_another_new_dest);
//and so on...
}
Upvotes: 1
Reputation: 24276
My recommendation is to upload one single file to the server and to make it available on multiple paths via .htaccess
. Something like:
RewriteRule ^/my-first-custom-path/(.*)$ /my-private-upload-directory/$1 [R=301,L]
RewriteRule ^/my-second-custom-path/(.*)$ /my-private-upload-directory/$1 [R=301,L]
Now, instead of accessing http://my-site.com/my-private-upload-directory/my-file.pdf
you will be able to download the file from both paths http://my-site.com/my-first-custom-path/my-file.pdf
and http://my-site.com/my-second-custom-path/my-file.pdf
Upvotes: 0