点击图片自动下载,请问代码如何写? 点击图片自动下载,请问代码如何写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function get_extension($file){ return substr(strrchr($file, '.'), 1); } function get_name($path){ return substr(strrchr($path, '/'), 1); } function getImage($url,$fileName="") { $fbufsize = 8096; $ext = get_extension($url); $fileName = get_name($url); $type = array( 'gif' => 'image/gif', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png', ); $imgType = isset($type[$ext])?$type[$ext]:die("类型不符"); header('Content-Description: File Transfer'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header("Content-type: ".$imgType); header("Content-Transfer-Encoding: binary"); header('Content-Disposition: attachment; filename="'.$fileName.'"'); header("Content-Length:" . getimagesize($url)."\n\n" ); $fp = fopen($url,"r"); while(!feof($fp)) { print(fread($fp,$fbufsize)); flush(); ob_flush(); } fclose($fp); exit; } getImage("http://www.lpfrx.com/wp-content/themes/ProSense/images/rss-feed-icon.jpg");下面我给说下怎么用,前端用JS控制,当点击图片时,如在onclick上进行跳转该到处理页,只需要一个该图片路径若用jquery更方便,举个例子$("img).click(function(){var path = $(this).attr("src");location.href="test.php?path="+path;})类似这样,把该path传过去就能下载了,测试过了,累死我了 神奇的没见过的技术大神们来围观啊!!!mysql一次自动插入2条数据,求解。。。。 [转]PHP中一些搞人的玩意:is_null,empty以及isset,unset的区别 PHP基础 PHP 复选框问题. 关于全文索引,普通索引和无索引,在中文和英文上;做了一组测试,但结果很让人迷茫;请高手指点! 请问如何注销自定义函数? 怎样用一段代码,嵌入它的网页能载入其它网页上的信息(如广告等)? apache验证有问题,请帮忙看看 请问:那里还有免费的竹叶空间(现如今,摇头叹气),国外的也行 生成静态页的问题? PHP 5.4.5 发布 高手进,大家看看这是如何实现的
function get_extension($file){
return substr(strrchr($file, '.'), 1);
}
function get_name($path){
return substr(strrchr($path, '/'), 1);
}
function getImage($url,$fileName="") {
$fbufsize = 8096;
$ext = get_extension($url);
$fileName = get_name($url);
$type = array(
'gif' => 'image/gif',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpe' => 'image/jpeg',
'png' => 'image/png',
);
$imgType = isset($type[$ext])?$type[$ext]:die("类型不符");
header('Content-Description: File Transfer');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header("Content-type: ".$imgType);
header("Content-Transfer-Encoding: binary");
header('Content-Disposition: attachment; filename="'.$fileName.'"');
header("Content-Length:" . getimagesize($url)."\n\n" );
$fp = fopen($url,"r");
while(!feof($fp)) {
print(fread($fp,$fbufsize));
flush();
ob_flush();
}
fclose($fp);
exit;
}
getImage("http://www.lpfrx.com/wp-content/themes/ProSense/images/rss-feed-icon.jpg");下面我给说下怎么用,前端用JS控制,当点击图片时,如在onclick上进行跳转该到处理页,只需要一个该图片路径
若用jquery更方便,举个例子
$("img).click(function(){
var path = $(this).attr("src");
location.href="test.php?path="+path;
})
类似这样,把该path传过去就能下载了,测试过了,累死我了