angularjs - How to use angular's $http to submit a form (including File type), and can the backend php use the $_FILES variable to obtain it?

WBOY
Release: 2016-08-10 09:07:17
Original
1053 people have browsed it

I want to upload a file, select a zip file, and pass it to the background php file through ajax. The php file can use $_FILES to get the file, but I don’t know how to implement it.

I tried not using $_FILES before, but using the following method to save the zip file

$input = file_get_contents("php://input",true); file_put_contents('temp/olin.zip',$input);
Copy after login
Copy after login

However, although the saved olin.zip file can be opened normally in the resource manager, there is a problem with the zip operation of php. Both zip_read and close will report errors. (The zip file generated without the previous two lines of code can operate normally)

Please tell me how to read $_FILES, or use php://input to generate a normal zip file.

Reply content:

I want to upload a file, select a zip file, and pass it to the background php file through ajax. The php file can use $_FILES to get the file, but I don’t know how to implement it.

I tried not using $_FILES before, but using the following method to save the zip file

$input = file_get_contents("php://input",true); file_put_contents('temp/olin.zip',$input);
Copy after login
Copy after login

However, although the saved olin.zip file can be opened normally in the resource manager, there is a problem with the zip operation of php. Both zip_read and close will report errors. (The zip file generated without the above two lines of code can operate normally)

Please tell me how to read $_FILES, or use php://input to generate a normal zip file.

The $http that comes with angularjs cannot be uploaded.
I tried it for a long time, and then I succeeded using native xhr. You can read the upload instructions in this article for the specific process.

angular file upload command

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!