Heim >Backend-Entwicklung >PHP-Tutorial >php怎么实现代理下载文件

php怎么实现代理下载文件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:06:141522Durchsuche

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
如果文件不大可以这样写

<br />$url = isset($_GET['url'])? $_GET['url'] : '';<br /><br />if($url){<br />    $content = file_get_contents($url);<br />    if($content){<br />        header('cache-control:public');<br />        header('content-type:application/octet-stream');<br />        header('content-disposition:attachment; filename='.basename($url));<br />        echo $content;<br />    }<br />}<br />

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:插入数据的有关问题Nächster Artikel:[ubuntu],该如何解决