关于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,安装安装了XAMPP后,出现了些问题,求大神帮帮忙 请问能否在网页中播放警报声? 关于MYSQL事务处理的疑问 在php页面中为什么get方法传递中文参数会出错? 怎样动态的决定类名 谁帮我封装下 win系统上的php内存不能完全释放内存探讨 关于文件的读写! 我想问一下phpmyadmin的语言编码自动选择是怎么实现的? 各位帮忙!!!!!!!!!! 尼玛,好苦逼啊,又被人逼的去搞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头输出的 是这个呗