View file wu-engine/wu-actions/adm_eshop_download.php

File size: 1.58Kb
<?php
require_once('../wu_init.php');
include('wu_checkadmin.php');
if (!USER_LOGGED) { exit('wu-error'); }

$id = intval($_GET['id']);
$sec = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT id,ty,fi,sec FROM ".DB_PREFIX."_es WHERE id='$id'"));
if ($sec['ty'] == 1) { exit('Неверный тип товара'); }
$fsize=filesize('../../eshop/items/'.$sec['sec']);
$fdown='../../eshop/items/'.$sec['sec'];
if (getenv('HTTP_RANGE')=="") {
$f=fopen($fdown, 'r');
if (ob_get_level()) {
ob_end_clean();
}
header("HTTP/1.1 200 OK");
header("Connection: close");
header("Content-Type: application/rar");
header("Accept-Ranges: bytes");
header("Content-Disposition: Attachment; filename=".$sec['fi']);
header("Content-Length: ".$fsize); 
while (!feof($f)) {
if (connection_aborted()) {
fclose($f);
break;
}
echo fread($f, 1000000);
sleep(1);
}
fclose($f);
}
else {
preg_match ("/bytes=(\d+)-/", getenv('HTTP_RANGE'), $m);
$csize=$fsize-$m[1]; // Размер фрагмента
$p1=$fsize-$csize; // Позиция, с которой начинать чтение файла
$p2=$fsize-1; // Конец фрагмента
$f=fopen($fdown, 'r');
if (ob_get_level()) {
ob_end_clean();
}
header("HTTP/1.1 206 Partial Content");
header("Connection: close");
header("Content-Type: application/rar");
header("Accept-Ranges: bytes");
header("Content-Disposition: Attachment; filename=".$sec['fi']);
header("Content-Range: bytes ".$p1."-".$p2."/".$fsize);
header("Content-Length: ".$csize);
fseek ($f, $p1);
while (!feof($f)) {
if (connection_aborted()) {
fclose($f);
break;
}
echo fread($f, 1000000);
sleep(1);
}
fclose($f);
}
?>