I'm trying to add a multi-file upload (with SWFUpload, obviously) form to a regular form that I'm using on my site. I can't figure out the following though:
For each file in the queue that was successfully uploaded, I want the file name to be stored in a hidden input field. There's only one hidden input, so the file names have to be appended each time.
Also, I'm saving the file on the server with a new, generated name.
So, say a user is uploading File-1.jpg, File-2.jpg and File-3.jpg after the queue has uploaded successfully i want the hidden input field to contain the following:
"file1-name-as-storedonserver.jpg, file2-name-as-storedonserver.jpg, file3-name-as-storedonserver.jpg"
I was looking through the forums and dug a bit through the sample code but couldn't find the right starting point yet. Any help would be greatly appreciated!
October 28, 2008 - 9:36am
You will need to use the uploadSuccess event.
Write an event handler:
function uploadSuccess(file, fileNameFromServer_AKA_serverData) {
var hiddenInputField = document.getElementById("myHiddenInputField");
hiddenInputField.value += fileNameFromServer_AKA_serverData;
}
and add this function to your SWFUpload settings.
In your server upload script (upload.php) you need to have it echo back the name of the file:
<?php
var savedFileName = saveTheFile($_FILE['Filedata']);
echo savedFileName;
?>
where the saveTheFile function does everything it needs to save the file and returns the new file name.
This little example assumes you'll never have any kind of server side upload error. But probably you will so you'll need to check for errors in your uploadSuccess function too.
October 29, 2008 - 10:55am
Thank you very much, works like a charm! Again, your help is greatly appreciated and keep up the good work. : )
April 26, 2009 - 5:05am
does not work for me
i get javascript errors in browser