Home >Backend Development >PHP Tutorial >php下载图片不完整解决方案

php下载图片不完整解决方案

WBOY
WBOYOriginal
2016-06-13 10:25:191675browse

php下载图片不完整
写了一个简易的下载单张图片的PHP文件:

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $url = $_POST ['url'];//$url="gallery/ddung/2.jpg";//要下载的图片链接DownImage($url);//下载url指向的图片function DownImage($url) {   $mime=getMime($url);  header("Content-Type: ".$mime);      $ext=getExt($url);  header("Content-Disposition: attachment; filename=".basename($url) );  header("Content-Transfer-Encoding: binary");  $fp=file($url);      foreach($fp as $fileLine)   {          echo $fileLine;    }}//获取要下载的图片的MIME信息function getMime($url){  if(preg_match("/\.(jpg|jpeg)$/",$url))    return "image/jpeg";  else if(preg_match("/\.(gif)$/",$url))    return "image/gif";  else if(preg_match("/\.(png)$/",$url))    return "image/png";  else if(preg_match("/\.(bmp)$/",$url))    return "image/bmp";  else    return "err";}//获取要下载的图片后缀名function getExt($url) {    if(preg_match("/\.(jpg|jpeg)$/",$url))    return "jpg";  else if(preg_match("/\.(gif)$/",$url))    return "gif";  else if(preg_match("/\.(png)$/",$url))    return "png";  else if(preg_match("/\.(bmp)$/",$url))    return "bmp";  else    return "err";}?>


提交后别人测试告诉我500k的图片只能下载200K = =
可是我没有限制下载大小啊~
请问大家可能是什么问题呢?


------解决方案--------------------
$fp=file($url);
foreach($fp as $fileLine) 
{
echo $fileLine;
}



改成这样看看
echo file_get_content

还有,前面不能有输出,你的代码最前一行 ------解决方案--------------------
读图片用file?? 原来图片也是一行一行的...

file_get_contents就行了。
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