<?php
//header("location:/files/a.ss")$file_name = "a.ss";
$file_dir = "files/";
$filename="aa.php";if (!file_exists($filename)) { 
echo "can't find file";
exit;

else {
$file = fopen($filename,"rb"); 
$size = filesize($filename);
header("Content-type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Accept-Length: $size");
header("Content-Disposition: attachment; filename=$filename");
echo fread($file,filesize($filename));
fclose($file);
exit;}
?>

解决方案 »

  1.   

    Do it like this!<?php
    $file="a_a.txt";
    $dest="a_a.txt";
    down_file($file,$dest);
    function down_file($content,$dest){
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=$dest" );
    header("Content-Transfer-Encoding: binary");
    //header("Content-Length: ".filesize($file));
    echo $content;
    }?>
      

  2.   

    测试了confu老兄的代码,为什么会有这样的错误呢??down.php 和 1.xls是在同一个目录。Warning: Cannot add header information - headers already sent by (output started at /var/www/down.php:2) in /var/www/down.php on line 9Warning: Cannot add header information - headers already sent by (output started at /var/www/down.php:2) in /var/www/down.php on line 10Warning: Cannot add header information - headers already sent by (output started at /var/www/down.php:2) in /var/www/down.php on line 11Warning: Cannot add header information - headers already sent by (output started at /var/www/down.php:2) in /var/www/down.php on line 12Warning: Cannot add header information - headers already sent by (output started at /var/www/down.php:2) in /var/www/down.php on line 13Warning: Cannot add header information - headers already sent by (output started at /var/www/down.php:2) in /var/www/down.php on line 14Warning: stat failed for (errno=2 - No such file or directory) in /var/www/down.php on line 15Warning: Cannot add header information - headers already sent by (output started at /var/www/down.php:2) in /var/www/down.php on line 15
    1.xls
      

  3.   

    直接 
    header("Location: $file");
    就可以了。我就这样做的。
      

  4.   

    header之前不能有输出,把header之前的输出去掉就没问题了,我原来也找过下载的问题,我贴的那个很好用的!