Просмотр файла www/upload.php

Размер файла: 1.84Kb
<?php

/**
 * @date 5.8
 * @author iceman12
 * @copyright 2010
 */

include 'system32/core.php';
if (isset($_FILES['file']['name']) and $_POST['hash']==$_SESSION['hash']) {
    sleep(2);
    unset($_SESSION['hash']);
    $_FILES['file']['name'] = input(preg_replace('/\0/s', '', $_FILES['file']['name'])); // от 0байта
    $original_name = $_FILES['file']['name']; // Оригинальное имя для записи в б.д.
    $ext = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION)); // узнаем расширение и переводим в нижний регистр
    if (in_array($ext, array('php', 'php3', 'php4', 'php5', 'php6', 'phtml', 'cgi',
        'asp', 'js', 'phtm', 'py', 'pl','htaccess')))
        $ext = 'txt'; // от злых дядек =))
    $name_file = mdQ(md5(mt_rand(1, 999999999) . mt_rand(1, 99999999))) . '.' . $ext; // имя для сохранения и по которому можно скачать файл
    if (copy($_FILES['file']['tmp_name'], 'superfile/' . $name_file)) {
        $_POST['name'] = isset($_POST['name']) ? mdQ($_POST['name']) : '';
        $_POST['password'] =( isset($_POST['password']) and $_POST['password'] != '') ?
            mdQ($_POST['password']) : '';
        $_POST['description'] = isset($_POST['description']) ? $_POST['description'] :
            '';
        $hash = substr(mdQ(md5(mt_rand(1, 999999999) . mt_rand(1, 99999999))), 22);
        sql("INSERT INTO `files`(`name`,`description`,`file`,`ip`,`password`,`hash`,`time`) VALUES('%s','%s','%s','%s','%s','%s','%s')",
            $original_name, $_POST['description'], $name_file, $_SERVER['REMOTE_ADDR'], $_POST['password'],
            $hash, $_SERVER['REQUEST_TIME']);
            $tpl->assign('hash',$hash);
        $tpl->display($style . '/upload.tpl');
    }

} else
    go();

?>