从服务器PHP下载后文件损坏

时间:2015-07-04 08:57:51

标签: php download torrent

我有从服务器下载torrent文件的脚本:

header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: private");
        header("Content-Description: File Transfer");
        header("Content-Type: application/x-bittorrent");
        header('Content-Length: '.filesize($local));
        header("Content-Disposition: attachment; filename=\"".$local."\"");
        $file = fopen($local, "r");
        print fread($file, filesize($local));
        fclose($file); 

如果我下载文件,洪流坏了,无法使用,任何人都可以帮助我吗? 错误是:

  

Torrent文件解码失败!请尝试重新下载torrent!

修改

$path = 'torrent/'; 
$local = $path.$row['file_src']; 

我做了一点改变

header('Cache-control: private');
    header('Content-Type: application/x-bittorrent');
    header('Content-Length: '.filesize($local));
    header('Content-Disposition: filename='.$download);
    $file = fopen($local, "r"); 
    print fread($file, filesize($local)); 
    fclose($file);

修改 对不起,但通常它没有问题,感谢@deceze,问题是在torrent文件中,下载后有一行下来。我怎么修这个?

1 个答案:

答案 0 :(得分:-1)

  header("Content-Disposition: attachment; filename=\"".$local."\"");

这一行是一个问题,因为您的标题文字包含在"中,但您的文件名子部分也包含在"中,因此代码无法理解使用相同引号的两个图层,因此而是将其更改为:

  header("Content-Disposition: attachment; filename='".$local."'");

这维护了标题的引用结构。

相关问题