Вход Регистрация
Файл: user/files/upload.php
Строк: 58
<?php

/* Мод "Файлы"
 * Версия v0.0.1
 * Дата последнего редактирования 30.01.2015
 * Двиг DCMS Special
 * Модифицировал densnet
 * Файл upload.php
 * Описание: выгрузка файлов
 */

require_once '../../sys/inc/start.php';
require_once 
H . 'sys/inc/compress.php';
require_once 
H . 'sys/inc/sess.php';
require_once 
H . 'sys/inc/settings.php';
require_once 
H . 'sys/inc/db_connect.php';
require_once 
H . 'sys/inc/ipua.php';
require_once 
H . 'sys/inc/fnc.php';
require_once 
H . 'sys/inc/user.php';

$set['title'] = 'Добавить файл'; // заголовок страницы

require_once H . 'sys/inc/thead.php';
user::only_reg();
title();
aut();

require_once 
'config.php';

function 
zam($am) {
    return 
strtr($am, " .&", "___");
}

$id_dir = intval($_GET['id']);
$dir_id = mysql_fetch_array(mysql_query("SELECT * FROM `user_dir` WHERE `id` = '$id_dir' LIMIT 1"));

if (
$dir_id['id_user'] == $user['id']) {
    if (isset(
$_GET['ok'])) {
        if (!isset(
$_FILES['file'])) {
            
$err = 'Ошибка при выгрузке файла';
        } else {
            
$file = text::esc(stripcslashes(htmlspecialchars($_FILES['file']['name'])));
            
$file = preg_replace('(#|?)', NULL, $file);
            
$name = preg_replace('#.[^.]*$#', NULL, $file); // имя файла без расширения
            
$imya = zam($name);
            
$ras = strtolower(preg_replace('#^.*.#', NULL, $file));
            
$size = filesize($_FILES['file']['tmp_name']);
            
$rasss = explode(';', $ras);
            
$ras_ok = false;

            for (
$i = 0; $i < count($rasss); $i++) {
                if (
$rasss[$i] != NULL && $ras == $rasss[$i]) {
                    
$ras_ok = true;
                }
            }
            if (!
$ras_ok) {
                
$err = 'Неверное расширение файла';
            }
        }
        
$opis = NULL;

        if (isset(
$_POST['opis'])) {
            
$opis = stripslashes(htmlspecialchars(text::esc($_POST['opis'])));
        }
        if (
mysql_result(mysql_query("SELECT COUNT(*) FROM `user_files` WHERE `dir` = '$id_dir' AND `name` = '$imya'"), 0) != 0) {
            
$err = 'Файл с таким названием уже есть в этой папке';
        }
        if (!isset(
$err)) {
            
mysql_query("INSERT INTO `user_files` (`dir`, `name`, `ras`, `size`, `time`, `id_user`, `opis` ) VALUES ('$id_dir', '$imya', '$ras', '$size', '$time', '$user[id]', '$opis' )");
            
$id_file = mysql_insert_id();
            if (!@
copy($_FILES['file']['tmp_name'], H . "sys/files/$id_file.dat")) {
                
mysql_query("DELETE FROM `user_files` WHERE `id` = '$id_file' LIMIT 1");
                
$err[] = 'Ошибка при выгрузке';
            }
            
header("location: dir.php?id=" . $user['id'] . "&dir=" . $id_dir . "");
        }
    }
    
err();

    echo 
"<div class = 'razd'>";
    echo 
"Папка: <b>$dir_id[name]</b>";
    echo 
"</div>";
    echo 
"<form class = 'razd' method = 'post' enctype = 'multipart/form-data' action = '?id=$_GET[id]&amp;dir=$_GET[dir]&amp;ok'>";
    echo 
"<b>Файл</b><br />";
    echo 
"<input name = 'file' type = 'file'/><br />";
    echo 
"<b>Описание</b><br />";
    echo 
"<textarea name = 'opis'></textarea><br />n";
    echo 
"<button class = 'button sign-ins'>Загрузить</button>";
    echo 
"<br />$ras";
    echo 
"</form>";
} else {
    
header("location: /index.php");
}

require_once 
H . 'sys/inc/tfoot.php';
Онлайн: 0
Реклама