php如何?代理下載檔案

來源:互聯網
上載者:User
假如a.com/a.rar在天朝無法訪問,如果寫一個a.php指令碼,放在海外伺服器上,訪問指令碼路徑b.com/a.php?url=http://a.com/a.rar
就可以實現檔案下載了,請問這個a.php檔案怎麼寫


回複討論(解決方案)

你確定 繞著彎就可以翻牆了?

http://www.cnblogs.com/sum41van/articles/1422450.html

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;    }}

要保證
1.天朝可以訪問b.com
2.b.com可以訪問a.com

可以使用 curl

$url = '傳入的目標url';$ch = curl_init(); //初始化curl_setopt($ch, CURLOPT_URL, $url);//curl_setopt($ch, CURLOPT_REFERER, '某個來路url'); //偽造來路頁面curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'func');curl_exec($ch); //執行function func($ch, $str) {  static $s = '@';  if($s) {    $s = trim($str);    if($s) header($s);  }else echo $str;  return strlen($str);}

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;    }}


謝謝親,如果能加入下載流量統計就好了

下載次數統計?

下載次數統計?

不是的。就是記錄通過這個檔案下載過的檔案大小加起來數值

把下載的功能,整合到方法裡面,執行一次就往資料表加1


下載次數統計?

不是的。就是記錄通過這個檔案下載過的檔案大小加起來數值



下??的檔案大小加起??
echo strlen($content);
可以?取大小後??在???。



下載次數統計?

不是的。就是記錄通過這個檔案下載過的檔案大小加起來數值



下??的檔案大小加起??
echo strlen($content);
可以?取大小後??在???。


謝謝啦,今天學了一天的html把代碼整合進去的作品




下載次數統計?

不是的。就是記錄通過這個檔案下載過的檔案大小加起來數值



下??的檔案大小加起??
echo strlen($content);
可以?取大小後??在???。


謝謝啦,今天學了一天的html把代碼整合進去的作品


http://qqgae.byethost16.com/1/

如問題解決了請結貼。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.