Файл: modules/forum/action/add_file_post.php
Строк: 155
<?php
/* DCMS Special
* Дата последнего редактирования 19.12.2015
* Модифицировал densnet
* Автор yadalay
*/
$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 {
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));
#Разрешил php файлы, так как необходимы они
if ($ras == 'exe' || $ras == 'js' || $ras == 'html' || $ras == 'htaccess' || $ras == NULL) {
echo "<div class='alert alert-danger'>Ошибка при выгрузке файла.</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="alert alert-success">Файл успешно прикреплён.</div>';
header('Location: ' . DIR_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="alert alert-success">Файл успешно удалён.</div>';
$file = mysql_fetch_object(mysql_query('SELECT `id`, `id_post`, `name` FROM `forum_post_files` WHERE `id` = ' . intval($_GET['del_file'])));
unlink(DIR_FORUM_FILES . $file->name);
mysql_query('DELETE FROM `forum_post_files` WHERE `id` = ' . $file->id);
header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '/' . $post->id . '/add_file');
exit;
}
if (isset($_SESSION['download'])) {
echo $_SESSION['download'];
unset($_SESSION['download']);
}
#Навигация
echo "<nav class='navbar navbar-light' style='background-color: #607D8B; color: #fff;'>";
echo "<ul class='nav navbar-nav'>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='/'><i class='material-icons'>home</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='" . DIR_FORUM . "'>Форум</a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='" . DIR_FORUM . "$forum->id/'>" . toOutput($forum->name, 1, 1, 0, 0, 0) . "</a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='" . DIR_FORUM . "$forum->id/$razdel->id/'>" . toOutput($razdel->name, 1, 1, 0, 0, 0) . "</a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id.html'>" . toOutput($theme->name, 1, 0, 0, 0, 0) . "</a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'>Добавление файла</a></li>";
echo "</ul>";
echo "</nav>";
$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') {
$icons = "<i class='material-icons'>insert_photo</i>";
} elseif ($ras == '3gp' || $ras == 'mp4' || $ras == 'avi' || $ras == 'mpeg' || $ras == 'flv' || $ras == 'wmv' || $ras == 'mkv') {
$icons = "<i class='material-icons'>video_library</i>";
} elseif ($ras == 'docx' || $ras == 'doc' || $ras == 'docm' || $ras == 'dotx' || $ras == 'dot' || $ras == 'dotm') {
$icons = "<i class='material-icons'>format_align_center</i>";
} elseif ($ras == 'mp1' || $ras == 'mp2' || $ras == 'mp3' || $ras == 'wav' || $ras == 'aif' || $ras == 'ape' || $ras == 'flac' || $ras == 'ogg' || $ras == 'asf' || $ras == 'wma') {
$icons = "<i class='material-icons'>library_music</i>";
} elseif ($ras == 'zip' || $ras == 'rar' || $ras == 'tar' || $ras == '7-zip' || $ras == 'gzip' || $ras == 'jar' || $ras == 'jad' || $ras == 'war' || $ras == 'xar') {
$icons = "<i class='material-icons'>archive</i>";
} elseif ($ras == 'txt' || $ras == 'xml') {
$icons = "<i class='material-icons'>format_align_justify</i>";
} elseif ($ras == 'pdf') {
$icons = "<i class='material-icons'>format_align_justify</i>";
} elseif ($ras == 'psd') {
$icons = "<i class='material-icons'>insert_photo</i>";
} else {
$icons = "<i class='material-icons'>insert_drive_file</i>";
}
$icon = DIR_FORUM_FILES . $p_file->name;
echo "<div class='list-group-item'>";
echo "<span style='float:right;'>";
echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/$post->id/del_file=$p_file->id' data-toggle='tooltip' data-placement='left' title='Удалить файл'><i class='material-icons'>delete</i></a>";
echo "</span>";
echo "<img src='$icon' style='width: 40px;height: 40px;padding:3px;' class='avatar'/> $icons " . toOutput($p_file->real_name) . " <font color='green'>" . size_file($p_file->size) . "</font> ";
echo "</div>";
}
echo "<form class='list-group-item' action='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/$post->id/add_file' method='post' enctype='multipart/form-data'>";
echo "<div class='file-field input-field'>";
echo "<div class='btn'><span>Файл</span>";
echo "<input name='file' type='file' multiple>";
echo "</div>";
echo "<div class='file-path-wrapper'>";
echo "<input class='file-path validate' type='text' placeholder='Выберите файл'>";
echo "</div>";
echo "</div>";
echo "<button name='download' class='waves-effect waves-light btn'><i class='material-icons'>attach_file</i> Прикрепить файл</button>";
echo "</form>";
require_once H . 'sys/inc/tfoot.php';
exit;
}