Reputation: 1863
Question:
I have a form with a textbox, file browse(uploadify) and a submit button. I am submitting this form via AJAX. When I select a file using file browser, it is automatically uploaded to a folder defined against folder option. Now after submitting form, I want to save data into database. I am able to get other fields data after post but unable to get uploaded files. I want an array of uploaded files in $_POST after submitting form like this:
$_POST( 'fullname'=>'ABC', 'uploaded_files' => array( '/uploads/abc.doc', '/uploads/xyz.doc' ) );
How it is possible ?
I have following implementation so far.
jQuery:
jQuery('.FileUpload').uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '/uploadify/uploadify.php',
'cancelImg' : '/uploadify/cancel.png',
'folder' : '/uploads',
'auto' : true,
'queueID' : 'fileQueue',
'removeCompleted':false
});
HTML:
<form action='save.php' method='POST' enctype='multipart/form-data'>
Name: <input type='text' name='fullname' id='fullname'>
Source File: <input type='file' name='photos' id='photos' class='FileUpload'>
<div id="fileQueue"></div>
<input type='submit' name='submit' id='submit'>
</form>
Upvotes: 2
Views: 4527
Reputation: 101604
Remember that uploadify has an onComplete
event that can return data back from your 'script'
parameter.
So, when uploadify passes the file off, you can then have the script return the path to the file storage location, and then retrieve/store it in your form based on what was passed back in the onComplete
event. (This would be the response portion of the onComplete
callback)
From there, you can populate hidden form fields that are them submitted with the form (as AurelioDeRosa has demonstrated) and populated with the response value(s).
Upvotes: 2
Reputation: 22152
Using javascript you can add some inputs to your form to trace the uploaded files. For example you can put:
<input type='hidden' name='files[]' value="FILENAME1">
<input type='hidden' name='files[]' value="FILENAME2">
<input type='hidden' name='files[]' value="FILENAME3">
Upvotes: 2