Home > Backend Development > PHP Tutorial > php接收二进制流保存图片解决方案

php接收二进制流保存图片解决方案

WBOY
Release: 2016-06-13 12:02:11
Original
1557 people have browsed it

php接收二进制流保存图片
现在做php接收iPad端传来的图片,保存并显示在后台,怎么接收啊并保存为图片啊,传过来是一二进制数据流传来的,求高手指点谢谢
------解决方案--------------------
直接写入图片就是了。file_put_contents("file.png", $data);
------解决方案--------------------

//取图片二进制<br />//将一张图片test.jpg 放在C 盘下<br />function imgData()<br />{<br />    $img_file = 'c:/test.jpg';<br />    $fp = fopen($img_file, 'rb');<br />    $content = fread($fp, filesize($img_file)); //二进制数据<br />    fclose($fp);<br />    return $content;<br />}<br />/**<br /> * 把二进制保存为图片<br /> * $dxycontent 图片二进制数据<br /> * $filepath 图片路径<br /> * $filename 图片名称<br /> */<br />function imgSave($dxycontent, $filepath, $filename)<br />{<br />    //得到post过来的二进制原始数据<br />    $file = fopen($filepath . $filename, "w"); //打开文件准备写入<br />    fwrite($file, $dxycontent); //写入<br />    fclose($file); //关闭   <br />}<br /><br />imgSave(imgData(),"d:/","test.jpg");<br />
Copy after login

------解决方案--------------------
<br />$stream = file_get_contents('php://input');<br /><br />$gd = imagecreatefromstring($stream);<br /><br />imagepng($gd, '/xxx.png');<br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template