How PHP implements agent download files

Source: Internet
Author: User
If A.com/a.rar can not be accessed in celestial, if write a a.php script, put on the overseas server, access the script path B.com/a.php?url=http://a.com/a.rar
You can implement the file download, how to write this a.php file


Reply to discussion (solution)

Are you sure you can turn over the wall around the bend?

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

B.com/a.php?url=http://a.com/a.rar
If the file is too small to write like this

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

To ensure that
1. Celestial can visit B.Com
2.b.com can access a.com

You can use Curl

$url = ' Incoming destination URL '; $ch = Curl_init (); Initialize curl_setopt ($ch, Curlopt_url, $url),//curl_setopt ($ch, Curlopt_referer, ' one routing URL '); Forge the Antecedents page curl_setopt ($ch, Curlopt_header, 1); curl_setopt ($ch, Curlopt_writefunction, ' func '); curl_exec ($ch); Execute 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
If the file is too small to write like this

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


Thank you pro, if you can join the download traffic statistics just fine

Download count?

Download count?

No. is to record the size of the file downloaded by this file plus the value.

Integrate the functionality of the download into the method and execute it once to add 1 to the data table


Download count?

No. is to record the size of the file downloaded by this file plus the value.



Next?? The file size added??
echo strlen ($content);
Can I take the size after?? In???.



Download count?

No. is to record the size of the file downloaded by this file plus the value.



Next?? The file size added??
echo strlen ($content);
Can I take the size after?? In???.


Thank you, today I learned a day of HTML to integrate code into the work




Download count?

No. is to record the size of the file downloaded by this file plus the value.



Next?? The file size added??
echo strlen ($content);
Can I take the size after?? In???.


Thank you, today I learned a day of HTML to integrate code into the work


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

If the problem is solved, please paste the knot.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.