关于PHP下载,请高手指点 PHP是否可以允许客户端在浏览器下载文件或者数据流(不通过activeX或者任何形式的DOM组件,脚本也不使用) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以发送过去,等对方操作->保存或取消(或运行)其实这个似乎怎么理解,图片本身就是非文本二进制文件,php能生成并在客户端浏览器显示一切似乎客户端放行条件 function download($file){ //$file文件路径 $len = filesize($file); $filename = basename($file); $file_extension = strtolower(substr(strrchr($filename,"."),1)); switch($file_extension){ case "zip": $ctype="application/zip"; break; case "rar": $ctype="application/rar"; break; case "sql": $ctype="application/sql"; break; case "xls": $ctype="application/vnd.ms-excel"; break; default: $ctype="application/force-download"; } //设置此页面的过期时间(用格林威治时间表示),只要是已经过去的日期即可。 //header("Expires: Mon, 26 Jul 1970 05:00:00 GMT"); //设置此页面的最后更新日期(用格林威治时间表示)为当天,可以强制浏览器获取最新资料 //header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //告诉客户端浏览器不使用缓存,HTTP 1.1 协议 header("Cache-Control: no-cache, must-revalidate"); //告诉客户端浏览器不使用缓存,兼容HTTP 1.0 协议 header("Pragma: no-cache"); //header("Cache-Control:"); //header("Cache-Control: public"); header("Content-Type: $ctype"); if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) { $iefilename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1); header("Content-Disposition: attachment; filename=\"$iefilename\""); }else{ header("Content-Disposition: attachment; filename=\"$filename\""); } header("Accept-Ranges: bytes"); $size=filesize($file); if(isset($_SERVER['HTTP_RANGE'])){ list($a, $range)=explode("=",$_SERVER['HTTP_RANGE']); str_replace($range, "-", $range); $size2=$size-1; $new_length=$size2-$range; header("HTTP/1.1 206 Partial Content"); header("Content-Length: $new_length"); header("Content-Range: bytes $range$size2/$size"); }else{ $size2=$size-1; header("Content-Range: bytes 0-$size2/$size"); header("Content-Length: ".$size); } $fp=fopen("$file","rb"); fseek($fp,$range); while(!feof($fp)){ set_time_limit(0); print(fread($fp,1024*8)); flush(); ob_flush(); } fclose($fp); }直接header头输出的 是这个呗 关于调用数据库中文乱码问题?奇怪的现象 php里的copy函数拷贝中文命名的文件 最近在用PHP搞一个MIS,现在才发现自己多差劲! php里面有没有函数可以操作linux里的账号 php中实现的链表有意义吗 php数据id可以显示,但传送不到另一页面 400分求一个高难度的PHP清缓存的解决方案... 拜托了 我的几个问题?? 哪位大虾能给我一份用session做的用户验证的原代码?!!(新手请教)急!!! 尼玛,好苦逼啊,又被人逼的去搞PHP,伤心,求高人指点一个弱智问题 phpexcel 导出的excel件保存下载问题
一切似乎客户端放行条件
function download($file){
//$file文件路径
$len = filesize($file);
$filename = basename($file);
$file_extension = strtolower(substr(strrchr($filename,"."),1));
switch($file_extension){
case "zip": $ctype="application/zip"; break;
case "rar": $ctype="application/rar"; break;
case "sql": $ctype="application/sql"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
default: $ctype="application/force-download";
}
//设置此页面的过期时间(用格林威治时间表示),只要是已经过去的日期即可。
//header("Expires: Mon, 26 Jul 1970 05:00:00 GMT");
//设置此页面的最后更新日期(用格林威治时间表示)为当天,可以强制浏览器获取最新资料
//header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
//告诉客户端浏览器不使用缓存,HTTP 1.1 协议
header("Cache-Control: no-cache, must-revalidate");
//告诉客户端浏览器不使用缓存,兼容HTTP 1.0 协议
header("Pragma: no-cache");
//header("Cache-Control:");
//header("Cache-Control: public");
header("Content-Type: $ctype");
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
$iefilename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1);
header("Content-Disposition: attachment; filename=\"$iefilename\"");
}else{
header("Content-Disposition: attachment; filename=\"$filename\"");
}
header("Accept-Ranges: bytes");
$size=filesize($file);
if(isset($_SERVER['HTTP_RANGE'])){
list($a, $range)=explode("=",$_SERVER['HTTP_RANGE']);
str_replace($range, "-", $range);
$size2=$size-1;
$new_length=$size2-$range;
header("HTTP/1.1 206 Partial Content");
header("Content-Length: $new_length");
header("Content-Range: bytes $range$size2/$size");
}else{
$size2=$size-1;
header("Content-Range: bytes 0-$size2/$size");
header("Content-Length: ".$size);
}
$fp=fopen("$file","rb");
fseek($fp,$range);
while(!feof($fp)){
set_time_limit(0);
print(fread($fp,1024*8));
flush();
ob_flush();
}
fclose($fp);
}直接header头输出的 是这个呗