0

我开发了一个从服务器下载 MP3 文件的代码。该代码适用于旧服务器,但不适用于新服务器。当我尝试下载罚款时它显示0字节

我通过 HTTP Post 方法发送下载链接

www.example.com/download.php?dlink=http://www.example.com/music/sample.mp3

这是我使用的代码

    ob_start();
    if(isset($_REQUEST['dlink']))
    {
        $file = $_REQUEST['dlink'];
        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;
    }
ob_flush();

提前致谢

4

1 回答 1

0

您不应该在 dlink 参数中传递绝对 url,因为您无法从远程服务器读取文件。

使用这个网址 www.example.com/download.php?dlink=music/sample.mp3

假设根目录中的可执行文件。

于 2012-05-16T07:33:24.587 回答