点击图片自动下载,请问代码如何写? 点击图片自动下载,请问代码如何写? 解决方案 » 免费领取超大流量手机卡,每月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传过去就能下载了,测试过了,累死我了 列表提交后能保持在当前页而不是刷新到首页 循环列印出的表单数值更新后再提交 $HTTP_POST_VARS和$_POST的区别? 大家帮我查询一下,这个搜索有什么问题? 我想问问,能不能设置文件夹的属性使文件夹中的文件能被其他页面包含但是不能直接执行? 怎么实现翻页显示啊? 请问如何转换\\为 \?谢谢! 关于php的form提交问题,在线等待. 一个很菜的问题:关于表单提交 关于跳转 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传过去就能下载了,测试过了,累死我了