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>
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">