function sendFile($serverPath, $filename, $mimeType = 'application/octet-stream')
{
        header("Content-Type: {$mimeType}");
        $filename = '"' . urlencode($filename) . '"';
        header("Content-Disposition: attachment; filename={$filename}");
        readfile($serverPath);
        exit;
    }

解决方案 »

  1.   

    还有就是如果直接定向到文件的话,文件类型只能是.rar的,其他的如.txt等会直接打开
      

  2.   

    test.php
    <?php
    header("Content-type: application/octet-stream");
    header("Content-disposition: attachment; filename=\"llll.jpg\"");?><input type="button" name="Submit7" value="下载到本地硬盘" onclick=location.href="test.php">
      

  3.   

    Warning: Cannot modify header information - headers already sent by...
    怎么出现这样的警告?
    能不能给出完整一点的代码
      

  4.   

    $filename为要下载的文件$filesize=filesize($filename);
                              header("Content-Type:text/plain");
                              header("Accept-Ranges:bytes");
                              header("Accept-Length:".filesize($filename));
                              header("Content-Disposition: attachment;filename=".basename($filename));
                            @$fp = fopen($filename, 'rb');
                          @flock($fp, 2);
                        $attachment = @fread($fp, $filesize);
                        @fclose($fp);
                              echo $attachment;