Please advise on the curl_exec problem in PHP. This post was last edited by easyrecovery8 from 2014-07-2508: 17: 46. the rar format of a compressed package on a network disk has a referer to detect anti-Leech, I want to put it on my blog for people to download, so I learned to forge a referer in PHP, but the result is a garbled string, it is estimated that the compressed package is output in the form of text to solve the curl_exec problem in PHP.
This post was last edited by easyrecovery8 at 08:17:46
The rar format of a compressed package on an online storage has a referer anti-Leech check. I want to put it on my blog for download. so I learned PHP to forge a referer, but the result is a garbled string, it is estimated that the compressed package is output in the form of text. I am a newbie. please kindly advise how to make it download in the form of opening the original connection.
My code is as follows:
$ Url = 'URL of a specific connection address in url.rar format ';
$ Ch = curl_init (); // Initialization
Curl_setopt ($ ch, CURLOPT_URL, $ url); // The page you want to access
Curl_setopt ($ ch, CURLOPT_REFERER, 'a specific url '); // forged webpage
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
$ Content = curl_exec ($ ch); // execute
Curl_close ($ ch); // Close
Echo $ content;
?>
------ Solution --------------------
You save the obtained results in the rar format. If yes, the content is correct. In this case, you only need to output the Header information:
header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=download.rar" );
------ Solution --------------------
Reference:
Quote: reference:
You save the obtained results in the rar format. If yes, the content is correct. In this case, you only need to output the Header information:
header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=download.rar" );
Thanks for downloading it!
But I changed the name of the original RAR file. for example, the original rar name is e-book .rar, but this is the downloaded character download.rar. Is there any way to save it as the original name?
This relationship needs to be analyzed by yourself
------ Solution --------------------
Well, that's not the case. the header becomes the body. To do this
Since the other party provides download, the relevant information is provided, including the file name and file length.
$ Url = '/url.rar format of a connection address ';
$ Ch = curl_init (); // Initialization
Curl_setopt ($ ch, CURLOPT_URL, $ url); // The page you want to access
Curl_setopt ($ ch, CURLOPT_REFERER, 'a specific url '); // forged webpage
Curl_setopt ($ ch, CURLOPT_HEADER, 1); // The http header to be read back.
Curl_setopt ($ ch, CURLOPT_WRITEFUNCTION, 'func'); // listen to the returned data
Curl_exec ($ ch); // execute
Function func ($ ch, $ str ){
Static $ s = '@';
If ($ s ){
$ S = trim ($ str );
If ($ s) header ($ s); // if it is a header information, the corresponding header is sent
} Else echo $ str; // otherwise, send data
Return strlen ($ str );
}
------ Solution --------------------
It is normal that Chinese file names are garbled
The server may be gbk or UTF-8 encoded
The client may also be gbk or UTF-8 encoded
When you receive header information such as Content-Disposition: attachment; filename=download.rar, make a judgment on the Chinese file name. if necessary, transcode the file according to the character set of the client.