1
我使用PHP来运行web服务。其中一个网址需要从POST正文中获取情侣图片。我目前使用的fopen/FREAD解决方案:如何通过file_get_contents查找流?
$size1 = intval($_REQUEST['img1']);
$size2 = intval($_REQUEST['img2']);
$sizeToRead = 4096;
$datas1 = null;
$datas2 = null;
$h = fopen('php://input','r+');
while($size1 > 0) {
if($sizeToRead > $size1)
$sizeToRead = $size1;
$datas1 .= fread($h,$sizeToRead);
$size1 -= $sizeToRead;
}
fclose($h);
file_put_contents('received1.png',$datas1);
//Same thing for the second image
这个解决方案工作正常,但我试图使其更具可读性使用file_get_contents()
:
file_put_contents('received1.png',file_get_contents('php://input',false,null,0,$size1));
但它给我一个错误:
的file_get_contents()流不支持查找
0123到位置
的file_get_contents()失败,寻求流
这甚至有可能在流中寻找?也许通过将第三个参数更改为其他内容?
如果没有,是否有办法让我的代码更优雅/高效?
谢谢。
如何file_get_contents()函数将做任何事情更具可读性? – 2013-03-15 14:58:09