Recently, because of the front-end separation, PHP
all APIs in the backend use RESTFul
style.
However, PUT
when using the upload file, found that $_FILES
there is no file information (may not upload temporary files, to be verified), use POST
is possible, and PUT
from 标准输入流
the obtained data, read out is the following format (above I guess not to upload temporary files, Because the standard input stream is stored with file information, it needs to be analyzed separately.
#获取到的输入流内容------WebKitFormBoundarybzEhWNCqbo9qKZBXContent-Disposition: form-data; name="upload"; filename="一些不错的职位.md"Content-Type: text/markdownxxxxxxxxxxxx------WebKitFormBoundarybzEhWNCqbo9qKZBX--
At present my train of thought is two:
If 上传
the temp file (this is being tested ...) ): If you upload, you can read the temporary file.
If the 不上传
temp file: Try to parse this string form-data
of arguments, but I do not know if this format has php
a corresponding method to parse.
Incidentally, there are often problems with the use of restful breathing:
In cross-domain, the normal form form (GET, POST) is fine, but if you use Put,delete, you need to set the cross-domain header.
PS: Do not understand, why need?
MDN HTTP method Document does not even have PUT
, DELETE
the details of ...
PHP gets PUT
, DELETE
needs to file_get_contents('php://input');
get parameter information, no similar $_PUT
, $_DELETE
global variables.
============= [22:01] ===================
To stackoverflow
stroll down, found that many encountered the same problem, temporarily did not see a better solution.
Added, this article jquery ajax put file, php save file, Blogger and I ran into the same problem, but he was using the regular to parse the data.
I was thinking, there is no better solution, can imitate PHP
processing POST
requests, the form-data
string, parse out, common parameters, save to $_PUT
( $_POST
), file to the temporary directory, and then return the file information to $_FILES
.
============ [10-10 10:16] ===================
This blog post how to use the Multipart/form-data format to upload files, there is a form-data format.
At present, the first simple to write a parsed form-data
composer
component.
Reply content:
Recently, because of the front-end separation, PHP
all APIs in the backend use RESTFul
style.
However, PUT
when using the upload file, found that $_FILES
there is no file information (may not upload temporary files, to be verified), use POST
is possible, and PUT
from 标准输入流
the obtained data, read out is the following format (above I guess not to upload temporary files, Because the standard input stream is stored with file information, it needs to be analyzed separately.
#获取到的输入流内容------WebKitFormBoundarybzEhWNCqbo9qKZBXContent-Disposition: form-data; name="upload"; filename="一些不错的职位.md"Content-Type: text/markdownxxxxxxxxxxxx------WebKitFormBoundarybzEhWNCqbo9qKZBX--
At present my train of thought is two:
If 上传
the temp file (this is being tested ...) ): If you upload, you can read the temporary file.
If the 不上传
temp file: Try to parse this string form-data
of arguments, but I do not know if this format has php
a corresponding method to parse.
Incidentally, there are often problems with the use of restful breathing:
In cross-domain, the normal form form (GET, POST) is fine, but if you use Put,delete, you need to set the cross-domain header.
PS: Do not understand, why need?
MDN HTTP method Document does not even have PUT
, DELETE
the details of ...
PHP gets PUT
, DELETE
needs to file_get_contents('php://input');
get parameter information, no similar $_PUT
, $_DELETE
global variables.
============= [22:01] ===================
To stackoverflow
stroll down, found that many encountered the same problem, temporarily did not see a better solution.
Added, this article jquery ajax put file, php save file, Blogger and I ran into the same problem, but he was using the regular to parse the data.
I was thinking, there is no better solution, can imitate PHP
processing POST
requests, the form-data
string, parse out, common parameters, save to $_PUT
( $_POST
), file to the temporary directory, and then return the file information to $_FILES
.
============ [10-10 10:16] ===================
This blog post how to use the Multipart/form-data format to upload files, there is a form-data format.
At present, the first simple to write a parsed form-data
composer
component.
PHP global variable $_files can only get post-uploaded files, if you want to use put to upload files, you must handle the stream yourself
On the mobile side, the current mainstream is Get+post+json
4, standard form data upload format
PHP put needs to be parsed separately, and put is generally used to accept JSON-formatted data
Thanks for the answer, in addition, the question was re-edited,:)