2012-05-16 193 views
0

我开发一个代码从服务器下载MP3文件。该代码在旧服务器中工作,但不适用于新服务器。它显示了0字节,当我尝试下载一个精细在php下载文件不起作用

我发送通过HTTP POST methos下载链接

www.example.com/download.php?dlink=http://www.example.com/音乐/ 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(); 

感谢代码

+0

什么是$文件这里读取文件($文件)? – Venu

+0

$ file = $ _REQUEST ['dlink']; 我错过了这一行,现在我添加了..请看看这个问题.... –

+0

你想输出文件,这是要获取另一台服务器?或者是位于该服务器中的文件? – Venu

回答

0

你不应该传递的绝对URL的参数DLINK,你无法读取远程SERV文件呃。

使用此URL www.example.com/download.php?dlink=music/sample.mp3

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

+0

感谢它工作正常..但相同的代码是通过传递绝对网址在另一台服务器上工作...多数民众赞成在这个问..这一切都谢谢先生 –

+0

关闭这张票如果你的问题通过接受这个答案解决 – Venu