Ralph Andreasen Ralph Andreasen - 5 months ago 58x
Javascript Question

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