简体   繁体   中英

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.

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. I'm using the sample PHP script, upload.php for processing.

It all works perfectly - except I am getting the original filename, which upload.php sanitises. 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.

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. Can anyone shed some light on this?

In line 53 of upload.php the sanitazation of the name and path ic complete:

$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);

If you want to use the filename in javascript, alter the JSON reply in line 130 to

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

so the filename is included. In Javascript you add a callback:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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