简体   繁体   English

Plupload:如何从 PHP 处理脚本中获取文件名

[英]Plupload: how to get filename from PHP processing script

I've just started using Plupload, which is great and really useful, however I'm falling down a bit tyring to customise it to my needs because it's just too far out of my depth.我刚刚开始使用 Plupload,它非常棒而且非常有用,但是我在根据我的需要定制它时有点费力,因为它超出了我的深度。

Basically I am using it to just upload a single file, so my code is based on the second of the two basic tutorials that are provided in the Plupload forum.基本上我只是使用它来上传单个文件,所以我的代码基于 Plupload 论坛中提供的两个基本教程中的第二个。 I'm using the sample PHP script, upload.php for processing.我正在使用示例 PHP 脚本 upload.php 进行处理。

It all works perfectly - except I am getting the original filename, which upload.php sanitises.一切都很完美——除了我得到了原始文件名,upload.php 可以清理。 So if there is, for example, a space in the filename, my form submission script doesn't work because it's looking for a file with the original name instead.因此,例如,如果文件名中有空格,我的表单提交脚本将不起作用,因为它正在寻找具有原始名称的文件。

I could obviously get this to work by removing or modifying the regular expression, but I don't really want to.我显然可以通过删除或修改正则表达式来使其工作,但我真的不想这样做。 I would much rather get back a sanitised filename from upload.php, but I'm just not sure how to go about doing this.我更愿意从upload.php 取回一个经过消毒的文件名,但我不确定如何去做。

I've searched on this subject in relation to Plupload, and can't find an answer, and I'm not able to search more generically for the same principle that I could apply because I don't even know quite what I'm looking for.我已经搜索了与 Plupload 相关的这个主题,但找不到答案,而且我无法更一般地搜索我可以应用的相同原则,因为我什至不知道我是什么寻找。 Can anyone shed some light on this?任何人都可以对此有所了解吗?

In line 53 of upload.php the sanitazation of the name and path ic complete:upload.php的第53行,名称和路径ic的清理完成:

$filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;

If you want to use the name in PHP, call a function right before it returns the success status (about line 130);如果您想在 PHP 中使用该名称,请在返回成功状态之前调用一个函数(大约第 130 行);

If you want to use the filename in javascript, alter the JSON reply in line 130 to如果要在 javascript 中使用文件名,请将第 130 行中的 JSON 回复更改为

die('{"jsonrpc" : "2.0", "result" : null, "id" : "id", "cleanFileName" : "'.$fileName.'"}');

so the filename is included.所以包含文件名。 In Javascript you add a callback:在 Javascript 中,您添加一个回调:

uploader.bind('FileUploaded', function(up, file, info) {
    console.log(info.response);
});

info.response is the JSON string returned and will include the filename after renaming on the server. info.response是返回的 JSON 字符串,将在服务器上重命名后包含文件名。

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

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