How to easily upload files without form submission (with jQuery + AJAX)

前端 未结 3 1226
渐次进展
渐次进展 2021-01-26 20:44

So I have some form processing code which processes the standard text inputs and also uploaded files (through the $_FILES array)

I want to have the submission done throu

3条回答
  •  囚心锁ツ
    2021-01-26 21:11

    To upload files via Ajax, you need to use a workaround using iframes or Flash.

    I recommend you Uploadify, it uses flash to do the uploading, and uses jQuery. I like the fact that it has many settings, and it comes with a nice default style for the queue handling. Just follow the instructions to set it up in your site.

    In the PHP script you'll receive the file in the $_FILES array, just like if it were a normal submission via a form, the default name is 'Filedata', so you can access your file via $_FILES['Filedata']. Then just echo the response for the Ajax request (JSON or XML), and execute some JS code for the Uploadify 'onComplete' event.

提交回复
热议问题