关于PHP实现文件下载 在ie6下有的文件无法下载,点击之后没有任何反应,有的文件就能下载,可以弹出ie自带的下载框,ie7 ie8 都能正常下载,不知道这是什么原因,请问有没有人遇到过这种问题,指点一下。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个是我的代码 $file_size = filesize($file_dir); $read=fopen($file_dir,"r"); header("Cache-Control:public,must-revalidate"); header("Pragma: public"); header( "Expires: 0" ); header("Content-Type: application/octet-stream"); header("Content-Length: " .$file_size); header('Content-Disposition:attachment;filename='.$name); echo fread($read,$file_size); fclose($read); exit; header("Content-Type: application/x-octet-stream");//改成这样试试?? header("Cache-Control: must-revalidate, post-check=0, div-check=0");从网上找的方法是说添加上这句话,可是这样之后,还是没有起任何作用。 $file_size = filesize($file_dir); $read=fopen($file_dir,"r"); header("Cache-Control:public,must-revalidate"); header("Pragma: public"); header( "Expires: 0" ); header("Content-Type: application/octet-stream"); header("Content-Length: " .$file_size); header('Content-Disposition:attachment;filename='.$name); echo fread($read,$file_size); fclose($read); exit;看不懂 解释下 把所有的header语句屏蔽,然后测试每一个链接,看哪个不能正常显示要下载的文件数据。再检测是什么原因。 把所有的header语句屏蔽掉之后,原来能正常下载的文件依旧能够输出,不能下载的文件依旧显示空白。求助。。IE6的噩梦!! //文件下载。function file_down($filepath, $filename = ''){ if(!$filename) $filename = basename($filepath); if(is_ie()) $filename = rawurlencode($filename); $filetype = fileext($filename); $filesize = sprintf("%u", filesize($filepath)); if(ob_get_length() !== false) @ob_end_clean(); header('Pragma: public'); header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: pre-check=0, post-check=0, max-age=0'); header('Content-Transfer-Encoding: binary'); header('Content-Encoding: none'); header('Content-type: '.$filetype); header('Content-Disposition: attachment; filename="'.$filename.'"'); header('Content-length: '.$filesize); readfile($filepath); exit;} Down.html<html><body><a href="http://localhost/filedown.php">DownLoad</a></body></html>file.php<?phpfunction file_down($filepath, $filename = ''){ if(!$filename) $filename = basename($filepath); $fileinfo = pathinfo($filename); $filetype = $fileinfo['extension']; if(ob_get_length() !== false) @ob_end_clean(); header('Pragma: public'); header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: pre-check=0, post-check=0, max-age=0'); header('Content-Transfer-Encoding: binary'); header('Content-Encoding: none'); header('Content-type: '.$filetype); header('Content-Disposition: attachment; filename="'.$filename.'"'); readfile($filepath); exit;} file_down("http://localhost/url.txt","url.txt");?>第二个是提供下载地址 $file = $file_dir;if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit;}这个是 php manual 上 的实例 试试这个吧function download($filename){ $timestamp=time(); ob_end_clean(); header('Last-Modified: '.gmdate('D, d M Y H:i:s',$timestamp+86400).' GMT'); header('Cache-control: max-age=86400'); header('Expires: '.gmdate('D, d M Y H:i:s',$timestamp+86400).' GMT'); header('Content-Encoding: none'); $basename = basename($filename); $fileext = substr(strrchr($basename,'.'),1); $filesize = filesize($filename); if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')!==false && $fileext=='torrent' ){ $attachment='inline'; } else{ $attachment='attachment'; } header('Content-Disposition: '.$attachment.'; filename='.$basename); header('Content-type: '.$fileext); $filesize && header('Content-Length: '.$filesize); readfile($filename); exit;} 清空下缓存header("prgram","no-cache"); header("Content-Lenght:".filesize($filename));试下 我觉得应该是IE6浏览器的问题,IE6本身的问题就有很多。 是不是有防盗链 如果是那样需要伪造Cookie 帮忙弄个正则表达式 关于PHP调用COM组件的问题 请教作过UC方面的高手!!!!! 关于php框架的问题,各位大虾帮帮忙! PHPLIB的mysql类在PHP5中嵌套出现问题?高手赐教 请大家介绍一下PHP的开发工具可以吗? 问题怎么总是解决不了呢 求一用session写的购物车类!! 对于判断多项选择,请教有没有更好的做法? 显示数据库里的图片在APACHE下可以,为什么在IIS下不行? (重新开帖)请教在WINDOWS+APACEH的环境下如何配置非线程安全的PHP环境 论坛内容采集
$file_size = filesize($file_dir);
$read=fopen($file_dir,"r");
header("Cache-Control:public,must-revalidate");
header("Pragma: public");
header( "Expires: 0" );
header("Content-Type: application/octet-stream");
header("Content-Length: " .$file_size);
header('Content-Disposition:attachment;filename='.$name);
echo fread($read,$file_size);
fclose($read);
exit;
header("Content-Type: application/x-octet-stream");//改成这样试试??
从网上找的方法是说添加上这句话,可是这样之后,还是没有起任何作用。
$read=fopen($file_dir,"r");
header("Cache-Control:public,must-revalidate");
header("Pragma: public");
header( "Expires: 0" );
header("Content-Type: application/octet-stream");
header("Content-Length: " .$file_size);
header('Content-Disposition:attachment;filename='.$name);
echo fread($read,$file_size);
fclose($read);
exit;看不懂 解释下
再检测是什么原因。
求助。。
IE6的噩梦!!
//文件下载。
function file_down($filepath, $filename = '')
{
if(!$filename) $filename = basename($filepath);
if(is_ie()) $filename = rawurlencode($filename);
$filetype = fileext($filename);
$filesize = sprintf("%u", filesize($filepath));
if(ob_get_length() !== false) @ob_end_clean();
header('Pragma: public');
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Content-Transfer-Encoding: binary');
header('Content-Encoding: none');
header('Content-type: '.$filetype);
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Content-length: '.$filesize);
readfile($filepath);
exit;
}
<body>
<a href="http://localhost/filedown.php">DownLoad</a>
</body>
</html>
file.php<?php
function file_down($filepath, $filename = '')
{
if(!$filename) $filename = basename($filepath);
$fileinfo = pathinfo($filename);
$filetype = $fileinfo['extension'];
if(ob_get_length() !== false) @ob_end_clean();
header('Pragma: public');
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Content-Transfer-Encoding: binary');
header('Content-Encoding: none');
header('Content-type: '.$filetype);
header('Content-Disposition: attachment; filename="'.$filename.'"');
readfile($filepath);
exit;
}
file_down("http://localhost/url.txt","url.txt");
?>第二个是提供下载地址
$file = $file_dir;
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
这个是 php manual 上 的实例
function download($filename){
$timestamp=time();
ob_end_clean();
header('Last-Modified: '.gmdate('D, d M Y H:i:s',$timestamp+86400).' GMT');
header('Cache-control: max-age=86400');
header('Expires: '.gmdate('D, d M Y H:i:s',$timestamp+86400).' GMT');
header('Content-Encoding: none');
$basename = basename($filename);
$fileext = substr(strrchr($basename,'.'),1);
$filesize = filesize($filename);
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')!==false && $fileext=='torrent' ){
$attachment='inline';
} else{
$attachment='attachment';
}
header('Content-Disposition: '.$attachment.'; filename='.$basename);
header('Content-type: '.$fileext);
$filesize && header('Content-Length: '.$filesize);
readfile($filename);
exit;
}
header("prgram","no-cache");