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