Вход Регистрация
Файл: modules/obmen/inc/upload_act.php
Строк: 62
<?php

/* DCMS Special
 * Дата последнего редактирования 15.12.2015
 * Модифицировал densnet
 */

if ($dir_id['upload'] == 1 && (!isset($set['obmen_limit_up']) || $set['obmen_limit_up'] <= $user['money'])) {
    if (isset(
$_GET['act']) && $_GET['act'] == 'upload' && isset($_GET['ok']) && $l != '/') {
        if (!isset(
$_FILES['file'])) {
            
$err[] = 'Ошибка при выгрузке файла';
        } elseif (!isset(
$_FILES['file']['tmp_name']) || filesize($_FILES['file']['tmp_name']) > $dir_id['maxfilesize']) {
            
$err[] = 'Размер файла превышает установленные ограничения';
        } else {
            
$file = esc(stripcslashes(htmlspecialchars($_FILES['file']['name'])));
            
$file = preg_replace('(#|?)', NULL, $file);
            
$name = preg_replace('#.[^.]*$#', NULL, $file); // имя файла без расширения
            
$ras = strtolower(preg_replace('#^.*.#', NULL, $file));
            
$type = $_FILES['file']['type'];
            
$size = filesize($_FILES['file']['tmp_name']);
            
$rasss = explode(';', $dir_id['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(esc($_POST['opis'])));
        }

        if (
mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_files` WHERE `id_dir` = '$dir_id[id]' AND `name` = '$name'"), 0)) {
            
$err[] = 'Файл с таким названием уже есть в этой папке';
        }

        if (!isset(
$err)) {
            
mysql_query("INSERT INTO `obmennik_files` (`id_dir`, `name`, `ras`, `type`, `size`, `time`, `time_last`, `id_user`, `opis` ) VALUES ('$dir_id[id]', '$name', '$ras', '$type', '$size', '$time', '$time', '$user[id]', '$opis' )");

            
$id_file = mysql_insert_id();

            if (!@
copy($_FILES['file']['tmp_name'], H . "sys/obmen/files/$id_file.dat")) {
                
mysql_query("DELETE FROM `obmennik_files` WHERE `id` = '$id_file' LIMIT 1");
                
$err[] = 'Ошибка при выгрузке';
            }

            
chmod(H . "sys/obmen/files/$id_file.dat", 0666);

            if (isset(
$_FILES['screen']) && preg_match('#.(GIF|JPE?G|PNG)$#i', $_FILES['screen']['name'], $scr_ras)) {
                
$scr_ras = str_replace('JPEG', 'JPG', strtoupper($scr_ras[1]));

                
move_uploaded_file($_FILES['screen']['tmp_name'], H . "sys/obmen/files/$id_file.dat.$scr_ras");
                @
chmod(H . "sys/obmen/files/$id_file.dat.$scr_ras", 0777);
            }
            
msg("Файл успешно выгружен");
        }
    }


    if (isset(
$_GET['act']) && $_GET['act'] == 'import' && isset($_GET['ok']) && $l != '/') {

        if (!isset(
$_POST['file'])) {
            
$err[] = 'Ошибка при выгрузке файла';
        } else {
            
$newfile = basename($_POST["file"]);
            
$name = preg_replace('#.[^.]*$#i', NULL, $newfile);
            
$ras = strtolower(preg_replace('#^.*.#i', NULL, $newfile));
            
$file = esc(stripcslashes(htmlspecialchars($_POST['file'])));
            
$file = preg_replace('(#|?)', NULL, $file);
            
$rasss = explode(';', $dir_id['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(esc($_POST['opis'])));
        }

        if (
mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_files` WHERE `id_dir` = '$dir_id[id]' AND `name` = '$name'"), 0)) {
            
$err[] = 'Файл с таким названием уже есть в этой папке';
        }

        if (!isset(
$err)) {

            
mysql_query("INSERT INTO `obmennik_files` (`id_dir`, `name`, `ras`, `time`, `time_last`, `id_user`, `opis` ) VALUES ('$dir_id[id]', '$name', '$ras', '$time', '$time', '$user[id]', '$opis' )");
            
$id_file = mysql_insert_id();
            if (!@
copy($_POST['file'], H . "sys/obmen/files/$id_file.dat")) {
                
mysql_query("DELETE FROM `obmennik_files` WHERE `id` = '$id_file' LIMIT 1");
                
$err[] = 'Ошибка при выгрузке';
            } else {
                
mysql_query("UPDATE `obmennik_files` SET `size` = '" . filesize(H . "sys/obmen/files/$id_file.dat") . "' WHERE `id` = '$id_file' LIMIT 1");
            }

            
chmod(H . "sys/obmen/files/$id_file.dat", 0666);

            if (isset(
$_FILES['screen']) && preg_match('#.(GIF|JPE?G|PNG)$#i', $_FILES['screen']['name'], $scr_ras)) {
                
$scr_ras = str_replace('JPEG', 'JPG', strtoupper($scr_ras[1]));
                
move_uploaded_file($_FILES['screen']['tmp_name'], H . "sys/obmen/files/$id_file.dat.$scr_ras");
                @
chmod(H . "sys/obmen/files/$id_file.dat.$scr_ras", 0777);
            }
            
msg("Файл успешно импортирован");
        }
    }
}
Онлайн: 2
Реклама