下面的代码在客户端下载文件时用迅雷现实的文件名是download.php,下载之后是正确的,想让迅雷现实的也是正确的文件名,请问该怎么解决?$basefname = $_GET['name'];
$fname = "downloadfiles/$basefname";
if ( file_exists( $fname ) ) {
    header( "content-type: audio/mpeg" );
    header( "content-disposition: attachment; filename=$basefname" );
    header( "content-length: ".filesize( $fname ) );
    echo file_get_contents( "$fname" );
}

解决方案 »

  1.   

    $basefname = $_GET['name'];
    $fname = "downloadfiles/$basefname";
    if ( file_exists( $fname ) ) {
        header( "content-type: audio/mpeg" );
        header( "content-disposition: attachment; filename=$basefname" );
        header( "content-length: ".filesize( $fname ) );
        echo file_get_contents( "$fname" );
    }
      

  2.   

    貌似你写的有点多。http://php.net/manual/en/function.header.php
    <?php
    // We'll be outputting a PDF
    header('Content-type: application/pdf');// It will be called downloaded.pdf
    header('Content-Disposition: attachment; filename="downloaded.pdf"');// The PDF source is in original.pdf
    readfile('original.pdf');
    ?>
      

  3.   

    五楼跟我的差不多,只不过我多做了一些处理。不过readfile要简洁些。
      

  4.   

    试试这个看看
    $basefname = $_GET['name'];
    $fname = "downloadfiles/$basefname";
    if ( file_exists( $fname ) ) {
        header("Location:".$fname);
    }
      

  5.   

    http://www.111cn.net/phper/php-gj/36287.htm
    看这个实例