[英]Download a file in php not working
I develop a code to download a MP3 file from server. 我开发了一个从服务器下载MP3文件的代码。 The code works in old server but not works in New Server. 该代码在旧服务器上有效,但在新服务器上无效。 It shows 0 bytes when i try to download a fine 当我尝试下载罚款时,它显示0个字节
i send a download link through HTTP Post methos 我通过HTTP Post方法发送下载链接
www.example.com/download.php?dlink=http://www.example.com/music/sample.mp3 www.example.com/download.php?dlink=http://www.example.com/music/sample.mp3
Here is the code i used 这是我使用的代码
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();
Thanks in advance 提前致谢
You should not pass the absolute url in dlink parameter as you cannot read file from remote server. 您不应在dlink参数中传递绝对URL,因为您无法从远程服务器读取文件。
use this url www.example.com/download.php?dlink=music/sample.mp3 使用此网址www.example.com/download.php?dlink=music/sample.mp3
assuming the executable file in root directory. 假定可执行文件位于根目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.