http-php put file, how to get the contents of the file?

Source: Internet
Author: User

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:

    1. If 上传 the temp file (this is being tested ...) ): If you upload, you can read the temporary file.

    2. 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:

    1. 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?

    2. MDN HTTP method Document does not even have PUT , DELETE the details of ...

    3. 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:

    1. If 上传 the temp file (this is being tested ...) ): If you upload, you can read the temporary file.

    2. 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:

    1. 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?

    2. MDN HTTP method Document does not even have PUT , DELETE the details of ...

    3. 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,:)

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.