Reputation: 4128
I'm using plupload to upload multiple files at once. I want to assign unique filenames on the serverside, and store it to backend during single file upload. (Storage has a flat namespace)
I want to generate a filename on the server backend, and pass this back to the client, in order for the client to post the full form, which includes a list of uploaded files (with appropriate filenames).
I am using the plupload queue widget example, but this appears to have a bug for multiple files with the same name. If I upload three files with the exact same name, the POST data on form submit will have three identical filenames, even though the upload.php in the example implementation (from zip file) renames the files to be file, file_1 and file_2.
How can I send this filename back to plupload in order to identify the file from form submit (with the upload_1_name post data)?
Upvotes: 0
Views: 1496
Reputation: 1
To make the filenames unique, I used this code:
$filePath = $targetDir . DIRECTORY_SEPARATOR . uniqid().$fileName;
uniqid()
is a shorter way of saying md5(microtime())
.
Upvotes: 0
Reputation: 1
Try this:
$filePath = $targetDir . DIRECTORY_SEPARATOR . md5(microtime()).$fileName;
Upvotes: 0
Reputation: 16726
You could set unique_names to true in your configuration. This will:
"...generate unqiue filenames for the files so that they don't for example collide with existing ones on the server."
Upvotes: 1