简体   繁体   中英

How to send the filename with Plupload?

I have been looking at this problem for quite some time now.

My problem is simple, i want to send the filename along with the file, as a multipart request in Plupload, but i have not been able to do it yet.

I need the full filename of the uploaded file, so i can save the file with the right file extention, in this case it is images only.

Here is what i have until now (JavaScript part):

BeforeUpload: function(up, file) {
    up.settings.multipart_params = {"name" : file.name, "gallery" : "9650f952-e397-11e5-8bca-d43d7e9e4e29"}
},

And in PHP i have this piece:

if (!empty($_FILES)) {
    $fileName = $_FILES["file"]["name"];
} elseif (isset($_REQUEST["name"])) {
    $fileName = $_REQUEST["name"];
} else {
    $fileName = uniqid("file_");
}
$filearr = explode ($fileName);
$ext = array_pop ($filearr);
$withoutext = implode ($filearr);

So, how does i fix this mess?

I should have been paying more attention to the code.

I found 2 errors, it is both the explode and implode functions that are missing a parameter, so the answer is simply this:

$filearr = explode (".",$fileName);
$ext = array_pop ($filearr);
$withoutext = implode (".",$filearr);

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