php下载图片不完整
写了一个简易的下载单张图片的PHP文件:
<!-- 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"; } ?>