3

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.

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.