|
|
|
@ -9,18 +9,37 @@ class Download { |
|
|
|
* |
|
|
|
* @return array Informations sur le transfert |
|
|
|
*/ |
|
|
|
static function get($url, $out) { |
|
|
|
static function get($url) { |
|
|
|
set_time_limit(0); |
|
|
|
|
|
|
|
$ch = curl_init($url); |
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); |
|
|
|
curl_setopt($ch, CURLOPT_HEADER, true); |
|
|
|
curl_setopt($ch, CURLOPT_NOBODY, true); |
|
|
|
curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); |
|
|
|
$res = curl_exec($ch); |
|
|
|
curl_close($ch); |
|
|
|
|
|
|
|
preg_match('/^HTTP\/1\.[01] (.*) .*/', $res, $matches); |
|
|
|
$retCode = $matches[1]; |
|
|
|
preg_match('/Content-Length: (.*)/', $res, $matches); |
|
|
|
$retLenght = $matches[1]; |
|
|
|
preg_match("/Content-Disposition: attachment; filename=\"(.*)\"; filename\*=UTF-8\'\'(.*)/", $res, $matches); |
|
|
|
$retFilename = $matches[1]; |
|
|
|
unset($matches); |
|
|
|
|
|
|
|
set_time_limit(0); |
|
|
|
$fp = fopen($out, 'w+');//This is the file where we save the information
|
|
|
|
$ch = curl_init($url);//Here is the file we are downloading, replace spaces with %20
|
|
|
|
curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file
|
|
|
|
$fp = fopen(DOWNLOADDIR.DIRECTORY_SEPARATOR.$retFilename, 'w+'); |
|
|
|
$ch = curl_init($url); |
|
|
|
curl_setopt($ch, CURLOPT_FILE, $fp); |
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
|
|
curl_exec($ch); // get curl response
|
|
|
|
curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); |
|
|
|
curl_exec($ch); |
|
|
|
$retour = curl_getinfo($ch); |
|
|
|
curl_close($ch); |
|
|
|
fclose($fp); |
|
|
|
|
|
|
|
return $retour; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//var_dump(Download::get('https://dl.sdv.fr/files/0/6/7/rubygem-csscss-1.0.0-1.fc18.src.rpm', 'Archive.zip'));
|
|
|
|
} |