PHP binary Image Conversion

Source: Internet
Author: User

First introduce:

$_post: An array of variables passed by the HTTP POST method. is an automatic global variable.

$GLOBALS [' Http_raw_post_data ']: always produces $HTTP _raw_post_data variable contains the original POST data. This variable is only generated when it encounters data that does not recognize the MIME type. $HTTP _raw_post_data is not available for enctype= ' multipart/form-data ' form data.

That is to say, basically $globals[' http_raw_post_data ' is the same as $_post.

But if the POST data is not recognized by PHP, you can use $GLOBALS [' Http_raw_post_data '] to receive it, such as text/xml or soap, etc.

Php://input allows the raw data to be read from the POST. Compared to $HTTP _raw_post_data, it brings less pressure to memory and does not require any special php.ini settings. Php://input cannot be used for enctype= "Multipart/form-data".

Problem:

Originally, I was thinking, what if I pass two binary pictures?

Later I was uploaded separately for each picture.

Scatter---------------------------------------------------------------------------------------------------------------------dividing line ------------------

$xmlstr = $GLOBALS [Http_raw_post_data]; Can be used to receive binary images,

if (empty ($xmlstr)) $xmlstr = file_get_contents (' php://input '); //This method is the same as above, and can be used to receive binary images

$jpg = $xmlstr;//get post binary raw data

$filename = "Test.jpg";

$file = fopen (".. /data/apps/". $filename," w ");//Open file ready to write

if (! $file) {

$res [' Code ']=0;

$res [' msg ']= ' upload image failed ';

exit;

}

fwrite ($file, $jpg);//write

fclose ($file);//Close


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.