Home  >  Article  >  Backend Development  >  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?

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
WBOYOriginal
2016-08-10 09:07:171057browse

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

<code>$input = file_get_contents("php://input",true);
file_put_contents('temp/olin.zip',$input);</code>

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

<code>$input = file_get_contents("php://input",true);
file_put_contents('temp/olin.zip',$input);</code>

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

Statement:
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