简体   繁体   English

plupload服务器分配的文件名

[英]Plupload server assigned file name

I'm using plupload to upload multiple files at once. 我正在使用plupload一次上传多个文件。 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. 我使用的是plupload queue窗口小部件示例,但这似乎对于具有相同名称的多个文件存在错误。 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. 如果我上传三个名称完全相同的文件,即使示例实现中的upload.php(来自zip文件)将文件重命名为file_1和file_2,表单提交上的POST数据也将具有三个相同的文件名。

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)? 我怎样才能将此文件名发送回plupload以便从表单提交(带有upload_1_name发布数据)中识别文件?

You could set unique_names to true in your configuration. 您可以在配置中将unique_names设置为true This will: 这将:

"...generate unqiue filenames for the files so that they don't for example collide with existing ones on the server." “ ...生成文件的文件名,这样它们就不会与服务器上的现有文件名发生冲突。”

尝试这个:

$filePath = $targetDir . DIRECTORY_SEPARATOR . md5(microtime()).$fileName;

To make the filenames unique, I used this code: 为了使文件名唯一,我使用了以下代码:

$filePath = $targetDir . DIRECTORY_SEPARATOR . uniqid().$fileName;

uniqid() is a shorter way of saying md5(microtime()) . uniqid()md5(microtime())的简短表达方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM