file download with curl and php -


i wrote php function downloads (.exe) files using curl extension. file gets downloaded, when try open not compatible error. opened using notepad++ , there see '200' added beginning of file. can't understand '200' comes ? here function:

$source = isset($_get['link']) ? $_get['link'] : ''; #get download link $filename = isset($_get['name']) ? $_get['name'] : 'download.exe'; # define name if($source != '') {             $handle = curl_init($source);             curl_setopt($handle,  curlopt_returntransfer, true);              /* html or whatever linked in $url. */             $response = curl_exec($handle);              /* check 403 (forbidden). */             $httpcode = curl_getinfo($handle, curlinfo_http_code);             if($httpcode == 403) {                 echo "<h2> <font color='red'> sorry not allowed download file.</font><h2>";             } else {                 header("content-disposition: attachment; filename=\"{$filename}\"");                 #header("content-disposition: attachment; filename=\"uploaded.pdf\"");                 // file url test document                  $url= str_replace(" ","%20", $source);                 $ch= curl_init($url);                 #curl_setopt($ch, curlopt_url, $url);                 curl_setopt($ch, curlopt_binarytransfer, true);                 curl_exec($ch);                 curl_close ($ch);               }             curl_close($handle); } else { echo "error"; } 

set curlopt_header false like:

curl_setopt($ch, curlopt_header, false); 

it disable http response, not receive '200' in file.

similar question here in so


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -