1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| # Copier d'un fichier binaire distant
function copyRemote($src,$dest)
{
// On essaye de forcer les limites du serveur..
@set_time_limit(0);
@max_execution_time(0);
// Si CURL est installé on l'utilise c'est mieux que les sockets.
if (function_exists('curl_init'))
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $src);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
$info = curl_exec($curl);
curl_close($curl);
}else{
// Sinon on utilise Fsocket mais il est limité sur les gros fichiers
$errno = 0;
$url = parse_url($src);
$errstr = $info = '';
$fichier = '';
$fichier .= ($url['path'] != '')? $url['path'] : '';
$fichier .= ($url['query'] != '')? '?'.$url['query'] : '';
$fsock = @fsockopen($url['host'], 80, $errno, $errstr, 10);
@fputs($fsock, "GET ".$fichier." HTTP/1.1\r\n");
@fputs($fsock, "HOST: ".$url['host']." \r\n");
@fputs($fsock, "Connection: close\r\n\r\n");
$get_info = false;
while (!@feof($fsock))
{
if ($get_info)
{
$info .= @fread($fsock, 1024);
}
else
{
if (@fgets($fsock, 1024) == "\r\n")
{
$get_info = true;
}
}
}
@fclose($fsock);
}
if (($fp2 = @fopen($dest,'w')) === false)
{
return ('Impossible d\'écrire les données du jeu sur le disque.');
}
else
{
fwrite($fp2,$info);
fclose($fp2);
return true;
}
} |
Partager