日期:2014-05-17 浏览次数:20464 次
<?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"; } ?>