{% else-1 %}

                        
function dnlf($dnlf){
if (headers_sent()) {
die('Заголовки отправлены');
}

if (ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}

if (file_exists($dnlf)){

$fsize = filesize($dnlf);
$path_parts = pathinfo($dnlf);
$ext = strtolower($path_parts['extension']);

$fd = @fopen($dnlf, 'rb');
$f1 = fileinode($dnlf);
$f2 = filemtime($dnlf);
$ftime = gmdate('r', $f2);

$arr_types = array(
"sis" => "application/vnd.symbian.install",
"amr" => "audio/amr",
"jad" => "text/vnd.sun.j2me.app-descriptor;charset=UTF-8",
"jar" => "application/java-archive",
"mp4" => "video/mp4",
"3gp" => "video/3gpp",
"rar" => "application/x-rar-compressed",
"doc" => "application/msword",
"exe" => "application/octet-stream",
"pdf" => "application/pdf",
"zip" => "application/zip",
"mp3" => "audio/mpeg",
"wav" => "audio/x-wav",
"bmp" => "image/bmp",
"gif" => "image/gif",
"jpg" => "image/jpeg",
"png" => "image/png",
"css" => "text/css",
"txt" => "text/plain",
"mpg" => "video/mpeg",
"avi" => "video/x-msvideo",
);

if (in_array($ext, $arr_types)) {
$type = $arr_types[$ext];
} else {
$type = 'application/force-download';
}

if (isset($_SERVER['HTTP_RANGE'])) {
$range = $_SERVER['HTTP_RANGE'];
$range = str_replace('bytes=', '', $range);
list($range, $end) = explode('-', $range);

if (!empty($range)) {
fseek($fd, $range);
}
} else {
$range = 0;
}

if ($range) {
header($_SERVER['SERVER_PROTOCOL'] . ' 206 Partial Content');
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK');
}

header('Last-Modified: ' . $ftime);
header('ETag: ' . sprintf('%x-%x-%x', $f1, $fsize, $f2));
header('Accept-Ranges: bytes');
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: ' . $type . '');
header('Content-Description: inline; File Transfer');
header('Content-Disposition: attachment; filename="' . basename($dnlf) . '";', false);
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . ($fsize - $range));

if ($range) {
header('Content-Range: bytes ' . $range . '-' . ($fsize - 1) . '/' . $fsize);
}

header('Connection: close');

ob_clean();

sleep(1);

$speed = 1024*8; // 8 - speed/kb
while(!feof($fd) && connection_status()==0) { // проверяем коннект, чтоб процесс не висел при дисконнекте
$buf = fread($fd, $speed); // отдаем файл порцайками , менее напрягает сервер, актуально для файлов более 1 гб
print($buf);
flush();
#sleep(1); // if speed > 8 разкоментирование приведет к ограничению скорости
}

fclose($fd);

} else {
die('Файл не найден!');
}

}
0 17 0
Без комментариев...