plupload get file name after uploading in PHP

William Contestabile picture William Contestabile · Aug 17, 2012 · Viewed 8k times · Source

I have added the pluploader to my PHP page and Im successfully uploading. On the same page I have a form that i am submiting on the page after people have uploaded some files. I would like the the uploader to add a hidden field onto the end of the form with the file name for each file that is uploaded. I have managed to get this half working with this in the script on the page

            uploader.bind('FileUploaded', function(up, file, info) {
            var obj = JSON.parse(info.response);
            $('form#quoteRequest').append('<input type="hidden" name="file_name" value="' + obj.cleanFileName + '" />');
        });

It seems to be adding the hidden field to the end of the form but with no file name. Perhaps someone knows whats going on here. I have been chopping and changing stuff but nothing seems to get the file name that was uploaded. I don't really know what i'm doing, very much in the early stages of learning PHP and this is a little bit above my head but im desperate for a good cross platform uploader and this seems to be the one.

Many thanks for your assistance.

info about plupload: http://www.plupload.com/

Answer

Waygood picture Waygood · Aug 17, 2012

in upload.php the last line needs to read as follows

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

Plupload does not automatically pass the filename back once complete.