How can I get the uploaded file details from uploadify after completion

php, uploadify

Solution

Do you know that you can get the `filename`, `filpath` inside the `onComplete` event like this:-

onComplete: function(event, queueID, fileObj, reponse, data) 
{
    alert fileObj.name; //The name of the uploaded file
    alert fileObj.filePath; //The path on the server to the uploaded file

    location.href= "complete.php?filename="+fileObj.name+"&filepath="+fileObj.filePath; //Here you can do a javascript redirect
}

Check the documentation for further details http://www.uploadify.com/documentation/events/oncomplete-2/

Are you looking for those values? If not let me know

Updates

As per your question updates, you have 2 options.

Either to do the "some process" after the file upload in the uploadify.php. You can see the file `uploadify.php` which comes with the uploadify plugin. There you have the `$_FILES['Filedata']` array containing all the file info. You may do the post processing here itself (by calling a function better instead of writing lots of code in uploadify's core code)

in uploadify.php $_FILES['Filedata']['name'] //file name

Or like I said, get the file name and path inside the `onComplete` event. Then pass these params like this :-

 location.href= "complete.php?filename="+fileObj.name+"&filepath="+fileObj.filePath;

I think this is better. You may send an ajax request instead to do the entire process (file upload + your "some process") without loading the page again. Write a $.post() request inside the `onComplete` event with those parameters and post to "complete.php"

Getting parameters inside `onComplete` which are not available by default

You have to use the `response` parameter available inside `onComplete` I worked on uploadify version 2.1.0 so my solution will work for sure on that version. If you want only one parameter, you can echo that at the end of `uploadify.php` I did the following thing:-

In my `uploadify.php` changed (this was in the original uploadify.php):-

move_uploaded_file($tempFile,$targetFile);
echo "1";

to this:-

move_uploaded_file($tempFile,$targetFile);
echo $tempFile;

and then inside the `onComplete` event did an explode -

var tmpName = reponse;

If however, you want to get more than one parameter inside `onComplete`, this is a trick I can give (this is not a good approach, but I was not able to return multiple params by any other way - I tried returning json array etc.):-

move_uploaded_file($tempFile,$targetFile);
echo $param1.'%%__%%'.$param2;

and then inside the `onComplete` event did an explode -

var paramsArray = explode('%%__%%',reponse);
param1 = paramsArray[0]; 
param2 = paramsArray[1]; 

Problem

How should I retrieve the uploaded file details from uploadify after the completion of the upload process. I want to do a process in the uploaded file. But when I use the uploadify it simply uploads the file to a location through the uploadify.php which I customized. I want this uploadify process to redirect to a page after completed with the details of the file such as filename and the targeted location where I will proceed with my second operation on the file uploaded Updates This is what my code as of now ``` <style type="text/css"> body { font: 0.8em/1.6em Arial, Helvetica, sans-serif; } fieldset { width: 500px; } #sample { display:table; } #sampleFile { float: left; display:table-cell; margin-right: 15px; } #download { margin-top: 15px; display: table; } .dlImage { display: table-cell; float: left; margin-right: 10px; } .dlText { float: left; display: table-cell; } .fileDetails { color: red; } .releaseDate{ margin-top: -3px; color: gray; } </style> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Uploadify scriptData Sample</title> <link rel="stylesheet" href="uploadify/uploadify.css" type="text/css" /> <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="js/jquery.uploadify.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#fileUpload").fileUpload({ 'uploader': 'uploadify/uploader.swf', 'cancelImg': 'uploadify/cancel.png', 'script': 'uploadify/upload.php', 'folder': 'files', 'multi': false, 'displayData': 'speed', 'onComplete' : function(event, queueID, fileObj, reponse, data) { location.href="complete.php"; } }); }); </script> </head> <body> <div id="sample"> <div id="sampleFile"> <fieldset style="border: 1px solid #CDCDCD; padding: 8px; padding-bottom:0px; margin: 8px 0"> <legend><strong>Sélectionner l'image à imprimer :</strong></legend> <div id="fileUpload">You have a problem with your javascript</div> <a href="javascript:$('#fileUpload').fileUploadStart()">Start Upload</a> <p></p> </fieldset> </div> </body> </html> ``` on the second page I do want to echo the file name that is uploaded I have there in the second page complete.php ``` <?php print_r($_FILES); echo $_FILES['type']; echo $_FILES['tmp_name']; echo $_FILES['name']; echo $_FILES['size']; ?> ```

Original source