php - Download file Curl with url var -


i download file curl. problem download link not direct, example:

http://localhost/download.php?id=13456 

when try download file curl, download file download.php!

here curl code:

 ### function downloadtorrent($a) { $save_to = $this->torrentfolder; // set torrent folder download $filename = str_replace('.torrent', '.stf', basename($a)); $fp = fopen ($this->torrentfolder.strtolower($filename), 'w+');//this file save information $ch = curl_init($a);//here file downloading curl_setopt($ch, curlopt_encoding, "gzip"); // important curl_setopt($ch, curlopt_timeout, 50); curl_setopt($ch, curlopt_url, $fp); curl_setopt($ch, curlopt_header,0); // none header curl_setopt($ch, curlopt_binarytransfer,1); // binary trasfer 1 curl_exec($ch); curl_close($ch); fclose($fp); } 

is there way download file without knowing path?

you may try curlopt_followlocation

true follow "location: " header server sends part of http header (note recursive, php follow many "location: " headers sent, unless curlopt_maxredirs set).

so result into:

function downloadtorrent($a) { $save_to = $this->torrentfolder; // set torrent folder download $filename = str_replace('.torrent', '.stf', basename($a)); $fp = fopen ($this->torrentfolder.strtolower($filename), 'w+');//this file save information $ch = curl_init($a);//here file downloading curl_setopt($ch, curlopt_encoding, "gzip"); // important curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_timeout, 50); curl_setopt($ch, curlopt_file, $fp); curl_setopt($ch, curlopt_header,0); // none header curl_setopt($ch, curlopt_binarytransfer,1); // binary transfer 1 curl_exec($ch); curl_close($ch); fclose($fp); } 

Comments

Popular posts from this blog

JQuery Autocomplete without using label, value, id -

c++ - Accessing inactive union member and undefined behavior? -

JAVA - what is the difference between void and boolean methods? -