Mr B
Mr B

Reputation: 4130

How to upload file via an AJAX form in Zend Framework 2?

I have an AJAX form in my ZF2 application. I want to handle file uploads. The JavaScript code I have written to handle the form submission can be found here. How do I send the uploaded file's details to my PHP script? My current code just sends the file name.

Appreciate any help.

Upvotes: 3

Views: 1814

Answers (2)

xeed
xeed

Reputation: 947

Checkout the new FileReader. It is already supported in most browsers. Basically it reads in the File you want to upload, so you can append it in a Post request as a string argument.

https://developer.mozilla.org/en-US/docs/Web/API/FileReader

Upvotes: 0

antyrat
antyrat

Reputation: 27765

You can't send files via AJAX. You will need to use hidden iframe for this for example. And make POST request to this iframe using target property.

Or without jQuery you can use XHR2 using FormData to reach this but it's supported only in modern browsers

Upvotes: 2

Related Questions