How to get uploaded files after form submit using uploadify?

99封情书 提交于 2020-01-02 09:38:33

问题


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>

回答1:


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



回答2:


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).



来源:https://stackoverflow.com/questions/7700989/how-to-get-uploaded-files-after-form-submit-using-uploadify

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!