Файл: modules/forum/action/add_file_post.php
Строк: 91
<?php
/* Мод "Форум"
* Версия v0.0.1
* Дата последнего редактирования 29.11.2014
* Двиг DCMS Special
* Модифицировал densnet
* Автор yadalay
* Файл add_file_post.php
* Описание: добавляет файлы к теме
*/
$post = mysql_fetch_object(mysql_query('SELECT `id`, `id_theme` FROM `forum_posts` WHERE `id` = ' . intval($_GET['post']) . ' AND `id_user` = ' . $user['id']));
$forum = mysql_fetch_object(mysql_query('SELECT `id`, `access`, `name` FROM `forum` WHERE `id` = ' . intval($_GET['forum'])));
$razdel = mysql_fetch_object(mysql_query('SELECT `id`, `id_forum`, `name` FROM `forum_razdels` WHERE `id_forum` = ' . $forum->id . ' AND `id` = ' . intval($_GET['razdel'])));
$theme = mysql_fetch_object(mysql_query('SELECT `id`, `id_razdel`, `name` FROM `forum_themes` WHERE `id_razdel` = ' . $razdel->id . ' AND `id` = ' . intval($_GET['theme'])));
if (!$theme || !$razdel || !$forum || !$post || ($forum->access == 1 && $user['group_access'] < 8) || ($forum->access == 2 && $user['group_access'] < 3)) {
header('Location: '.DIR_FORUM);
exit;
} else {
$set['title'] = 'Добавление файлов';
require_once H.'sys/inc/thead.php';
title() . aut();
if (isset($_POST['download'])) {
$file = mysql_real_escape_string(stripcslashes($_FILES['file']['name']));
$file = preg_replace('(#|?)', NULL, $file);
$name = preg_replace('#.[^.]*$#', NULL, $file);
$size = filesize($_FILES['file']['tmp_name']);
$ras = strtolower(preg_replace('#^.*.#', NULL, $file));
if ($ras == 'php' || $ras == 'exe' || $ras == 'js' || $ras == 'html' || $ras == 'htaccess' || $ras == NULL) {
echo "<div class = 'errs'>Ошибка при выгрузке файла.</div>";
} else {
$count_files = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_post_files` WHERE `id_post` = ' . $post->id), 0);
mysql_query('INSERT INTO `forum_post_files` SET `id_theme` = ' . $theme->id . ', `id_post` = ' . $post->id . ', `id_user` = ' . $user['id'] . ', `name` = "' . $post->id . '_' . ($count_files + 1) . '.' . $ras . '", `real_name` = "' . $file . '", `size` = ' . $size);
move_uploaded_file($_FILES["file"]["tmp_name"], 'files/' . $post->id . '_' . ($count_files + 1) . '.' . $ras);
$_SESSION['download'] = '<div class = "msgs">Файл успешно прикреплён.</div>';
header('Location: /modules/forum/' . $forum->id . '/' . $razdel->id . '/' . $theme->id . '/' . $post->id . '/add_file');
exit;
}
} elseif (isset($_GET['del_file']) && (mysql_fetch_object(mysql_query('SELECT `id_user` FROM `forum_post_files` WHERE `id` = ' . intval($_GET['del_file'])))->id_user == $user['id'] || user_access('forum_post_ed'))) {
$_SESSION['download'] = '<div class = "msgs">Файл успешно удалён.</div>';
$file = mysql_fetch_object(mysql_query('SELECT `id`, `id_post`, `name` FROM `forum_post_files` WHERE `id` = ' . intval($_GET['del_file'])));
unlink('/modules/forum/files/' . $file->name);
mysql_query('DELETE FROM `forum_post_files` WHERE `id` = ' . $file->id);
header('Location: /modules/forum/' . $forum->id . '/' . $razdel->id . '/' . $theme->id . '/' . $post->id . '/add_file');
exit;
}
if (isset($_SESSION['download'])) {
echo $_SESSION['download'];
unset($_SESSION['download']);
}
#Навигация
echo "<div class = 'navigation'><a href = '/index.php'>Главная</a> > <a href = '" . DIR_FORUM . "'>Форум</a> > <a href = '" . DIR_FORUM . "$forum->id/'>" . text::toOutput($forum->name, 1, 1, 0, 0, 0) . "</a> > <a href = '" . DIR_FORUM . "$forum->id/$razdel->id/'>" . text::toOutput($razdel->name, 1, 1, 0, 0, 0) . "</a> > <b><a href = '".DIR_FORUM."$forum->id/$razdel->id/$theme->id.html'>" . text::toOutput($theme->name, 1, 1, 0, 0, 0) . "</a></b></div>";
$files = mysql_query('SELECT * FROM `forum_post_files` WHERE `id_post` = ' . $post->id);
while ($p_file = mysql_fetch_object($files)) {
$ras = strtolower(preg_replace('#^.*.#', NULL, $p_file->name));
if ($ras == 'jpg' || $ras == 'jpeg' || $ras == 'gif' || $ras == 'png' || $ras == 'bmp' || $ras == 'ico') {
$icon = '/modules/forum/files/' . $p_file->name;
} elseif ($ras == '3gp' || $ras == 'mp4' || $ras == 'avi' || $ras == 'mpeg' || $ras == 'flv' || $ras == 'wmv' || $ras == 'mkv') {
$icon = '/modules/forum/icons/files/video.png';
} elseif ($ras == 'docx' || $ras == 'doc' || $ras == 'docm' || $ras == 'dotx' || $ras == 'dot' || $ras == 'dotm') {
$icon = '/modules/forum/icons/files/word.png';
} elseif ($ras == 'mp1' || $ras == 'mp2' || $ras == 'mp3' || $ras == 'wav' || $ras == 'aif' || $ras == 'ape' || $ras == 'flac' || $ras == 'ogg' || $ras == 'asf' || $ras == 'wma') {
$icon = '/modules/forum/icons/files/music.png';
} elseif ($ras == 'zip' || $ras == 'rar' || $ras == 'tar' || $ras == '7-zip' || $ras == 'gzip' || $ras == 'jar' || $ras == 'jad' || $ras == 'war' || $ras == 'xar') {
$icon = '/modules/forum/icons/files/archive.png';
} elseif ($ras == 'txt' || $ras == 'xml') {
$icon = '/modules/forum/icons/files/txt.png';
} elseif ($ras == 'pdf') {
$icon = '/modules/forum/icons/files/pdf.png';
} elseif ($ras == 'psd') {
$icon = '/modules/forum/icons/files/psd.png';
} else {
$icon = '/modules/forum/icons/files/file.png';
}
echo "<table class = 'post' cellspacing = '0' cellpadding = '0'>";
echo "<tr><td class = 'razd' style = 'width: 50px; border-right: none'>";
echo "<a href = '$icon'><img src = '$icon' alt = '' style = 'width: 50px; height: 50px' /></a>";
echo "</td><td class = 'razd' style = 'border-left: none'>";
echo text::toOutput($p_file->real_name) . "<br />";
echo "Размер файла: " . size_file($p_file->size) . "<br />";
echo "[ <a href = '".DIR_FORUM."$forum->id/$razdel->id/$theme->id/$post->id/del_file=$p_file->id'>Удалить файл</a> ]";
echo "</td></tr></table>";
}
echo "<form class = 'razd' action = '".DIR_FORUM."$forum->id/$razdel->id/$theme->id/$post->id/add_file' method = 'post' enctype = 'multipart/form-data'>";
echo "<input type = 'file' name = 'file' /><br />";
echo "<button name = 'download' class = 'clik'>Добавить файл</button>";
echo "</form>";
require_once H.'sys/inc/tfoot.php';
exit;
}