当前位置:Gxlcms > PHP教程 > php怎么实现代理下载文件

php怎么实现代理下载文件

时间:2021-07-01 10:21:17 帮助过:4人阅读

php如何实现代理下载文件
假如a.com/a.rar在天朝无法访问,如果写一个a.php脚本,放在海外服务器上,访问脚本路径b.com/a.php?url=http://a.com/a.rar
就可以实现文件下载了,请问这个a.php文件怎么写
------解决方案--------------------
b.com/a.php?url=http://a.com/a.rar
如果文件不大可以这样写

$url = isset($_GET['url'])? $_GET['url'] : '';

if($url){
$content = file_get_contents($url);
if($content){
header('cache-control:public');
header('content-type:application/octet-stream');
header('content-disposition:attachment; filename='.basename($url));
echo $content;
}
}

人气教程排行