File size: 2.83Kb
<?php
$dir_clean = opendir('time_files/created_zip');
while ($file = readdir($dir_clean)) {
if ($file != 'index.php' && $file != '.htaccess' && $file != '.' && $file != '..') {
$time_file = filemtime('time_files/created_zip/' . $file);
if ($time_file < ($time - 300))
unlink('time_files/created_zip/' . $file);
}
}
closedir($dir_clean);
$req_down = mysql_query("SELECT * FROM `down_files` WHERE `id` = '$id' AND (`type` = 2 OR `type` = 3) LIMIT 1");
$res_down = mysql_fetch_assoc($req_down);
if (mysql_num_rows($req_down) == 0 || !is_file($res_down['dir'] . '/' . $res_down['name']) || format($res_down['name']) != 'txt' || ($res_down['type'] == 3 && !$admin)) {
include H.'engine/includes/head.php'; echo display_error('Файл не найден<br /><a href="index.php">К категориям</a>');
include H.'engine/includes/foot.php';
}
if (isset($_GET['more'])) {
$more = abs(intval($_GET['more']));
$req_more = mysql_query("SELECT * FROM `down_more` WHERE `id` = '$more' LIMIT 1");
$res_more = mysql_fetch_assoc($req_more);
if (!mysql_num_rows($req_more) || !is_file($res_down['dir'] . '/' . $res_more['name']) || format($res_more['name']) != 'txt') {
include H.'engine/includes/head.php'; echo display_error('Файл не найден<br /><a href="index.php">К категориям</a>');
include H.'engine/includes/foot.php';
exit;
}
$down_file = $res_down['dir'] . '/' . $res_more['name'];
$title_pages = $res_more['rus_name'];
$txt_file = $res_more['name'];
}
else {
$down_file = $res_down['dir'] . '/' . $res_down['name'];
$title_pages = $res_down['rus_name'];
$txt_file = $res_down['name'];
}
if (!isset($_SESSION['down_' . $id])) {
mysql_query("UPDATE `down_files` SET `field`=`field`+1 WHERE `id`='$id'");
$_SESSION['down_' . $id] = 1;
}
$file = 'time_files/created_zip/' . $txt_file . '.zip';
if (!file_exists($file)) {
require_once H.'sys/inc/zip.php';
$zip = new PclZip($file);
function w($event, &$header)
{
$header['stored_filename'] = basename($header['filename']);
return 1;
}
$zip->create($down_file, PCLZIP_CB_PRE_ADD, 'w');
chmod($file, 0644);
}
include H.'engine/includes/head.php';
echo '<div class="p_m"><b>' . output_text($title_pages) . '</b></div>';
echo '<div class="menu"><a href="' . output_text($file) . '">Скачать в ZIP</a></div>';
echo '<div class="menu"><input type="text" value="http://'.$_SERVER['HTTP_HOST'].'/' . $dir_load . '/' . output_text($file) . '"/><b></b></div>';
echo '<div class="menu">Файл будет доступен для скачивания в течение 5 минут</div>';
echo '<div class="p_t"><a href="index.php?act=view&id=' . $id . '">К файлу</a></div>';
?>