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 59 60 61
| $url = $_POST['url'];
//recuperation du size du fichier
$remoteFile = $url;
$ch = curl_init($remoteFile);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //not necessary unless the file redirects (like the PHP example we're using here)
$data = curl_exec($ch);
curl_close($ch);
if ($data === false) {
echo 'cURL failed';
exit;
}
$contentLength = 'unknown';
$status = 'unknown';
if (preg_match('/^HTTP\/1\.[01] (\d\d\d)/', $data, $matches)) {
$status = (int)$matches[1];
}
if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {
$contentLength = ((int)$matches[1])/1000;
}
// --
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
global $url;
echo filesize("gecici/".basename($url));
//global $contentLength;
$key = $_POST['APC_UPLOAD_PROGRESS'];
$total = $bytes_transferred;
$array = array (
'total' => $bytes_max,
'current' => $bytes_transferred
);
apc_store($key, $array);
// echo $total."<br>";
}
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
$file = fopen ($url, "rb", false, $ctx);
if ($file) {
$newf = fopen ("gecici/".basename($url), "wb");
if ($newf)
while(!feof($file)) {
fwrite($newf, fread($file, $contentLength ), $contentLength );
}
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
} |
Partager