Je voudrais télcharger un fichier en utilisant cURL, le fichier ne se télecharge pas, et ouvre seulement la page qui force le télechargement:
Lien du télechargement:
<?php
echo '<a href="Files/direct_download.php?path=../'.$path2file.'/&file='.$fileName.'" id="'.$id.'" style="cursor: pointer;" target="_BLANK">Download using cuRL</a>';
?>
direct_download.php:<?php
$url = strip_tags($_GET['path']);
//echo $url.'<br>';
$fileName = strip_tags($_GET['file']);
//echo 'url '.$url.'<br >';
//echo 'file '.$fileName.'<br >';
set_time_limit(0);
$fp = fopen (dirname(__FILE__) . '/localfile.tmp', 'w+');//This is the file where we save the information
$ch = curl_init(str_replace(" ","%20",$url.$fileName));//Here is the file we are downloading, replace spaces with %20
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch); // get curl response
curl_close($ch);
fclose($fp);
?>
Merci pour votre aide