PHP receives binary stream save picture solution

Source: Internet
Author: User
PHP receives binary stream save picture
Now do PHP to receive pictures from the ipad, save and display in the background, how to receive AH and save as a picture ah, passed over is the twos into the data circulated, seeking expert guidance Thank you
------Solution--------------------
Just write the picture. File_put_contents ("File.png", $data);
------Solution--------------------
Take picture binary
Put a picture test.jpg under the C drive
function Imgdata ()
{
$img _file = ' c:/test.jpg ';
$fp = fopen ($img _file, ' RB ');
$content = Fread ($fp, FileSize ($img _file)); Binary data
Fclose ($FP);
return $content;
}
/**
* Save the binary as a picture
* $dxycontent Picture binary data
* $filepath Picture Path
* $filename Picture Name
*/
function Imgsave ($dxycontent, $filepath, $filename)
{
Get the binary raw data from the post.
$file = fopen ($filepath. $filename, "w"); Open file ready to write
Fwrite ($file, $dxycontent); Write
Fclose ($file); Shut down
}

Imgsave (Imgdata (), "d:/", "test.jpg");

------Solution--------------------

$stream = file_get_contents (' php://input ');

$GD = imagecreatefromstring ($stream);

Imagepng ($GD, '/xxx.png ');
  • 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.