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

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

WBOY
WBOYOriginal
2016-06-13 12:02:111542browse

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 />

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

Statement:
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
Previous article:PHP模板解决办法Next article:表单解决方案