Вход Регистрация
Файл: muzxit.ru/stars/addfile.php
Строк: 115
<?php

/**
 * @package     JohnCMS
 * @link        http://johncms.com
 * @copyright   Copyright (C) 2008-2011 JohnCMS Community
 * @license     LICENSE.txt (see attached file)
 * @version     VERSION.txt (see attached file)
 * @author      http://johncms.com/about
 */

define('_IN_JOHNCMS'1);
$headmod 'stars';require('../incfiles/core.php');
$lng_stars core::load_lng('stars');
$lng_forum core::load_lng('forum');
if (isset(
$_SESSION['ref']))
    unset(
$_SESSION['ref']);
// Задаем заголовки страницы
$textl $lng_stars['stars'];    

require(
'../incfiles/head.php');

/*
-----------------------------------------------------------------
Список расширений файлов, разрешенных к выгрузке
-----------------------------------------------------------------
*/
// Файлы картинок
$ext_pic = array(
    
'jpg',
    
'jpeg',
    
'gif',
    
'png',
    
'bmp'
);


if (
$rights 8) {
    echo 
functions::display_error($lng['error_wrong_data']);
    require(
'../incfiles/end.php');
    exit;
}
$req mysql_query("SELECT * FROM `stars` WHERE `id` = '$id'");
$res mysql_fetch_assoc($req);
$cats2 mysql_fetch_assoc(mysql_query("select * from `stars` where `id` = '$res[cid]';"));
$cats3 $cats2['cid'] != mysql_fetch_assoc(mysql_query("select * from `stars` where `id` = '$cats2[cid]';")) : null;
        if (isset(
$_POST['submit'])) {
            
/*
            -----------------------------------------------------------------
            Проверка, был ли выгружен файл и с какого браузера
            -----------------------------------------------------------------
            */
            
$do_file false;
            
$do_file_mini false;
            if (
$_FILES['fail']['size'] > 0) {
                
// Проверка загрузки с обычного браузера
                
$do_file true;
                
$fname strtolower($_FILES['fail']['name']);
                
$fsize $_FILES['fail']['size'];
            } elseif (
strlen($_POST['fail1']) > 0) {
                
// Проверка загрузки с Opera Mini
                
$do_file_mini true;
                
$array explode('file='$_POST['fail1']);
                
$fname strtolower($array[0]);
                
$filebase64 $array[1];
                
$fsize strlen(base64_decode($filebase64));
            }
            
/*
            -----------------------------------------------------------------
            Обработка файла (если есть), проверка на ошибки
            -----------------------------------------------------------------
            */
            
if ($do_file || $do_file_mini) {
                
// Список допустимых расширений файлов.
                
$al_ext array_merge($ext_win$ext_java$ext_sis$ext_doc$ext_pic$ext_arch$ext_video$ext_audio$ext_other);
                
$ext explode("."$fname);
                
$fname $id.'.'.$ext[1];
                
$error = array();
                
// Проверка на допустимый размер файла
                
if ($fsize 1024 $set['flsz'])
                    
$error[] = $lng_forum['error_file_size'] . ' ' $set['flsz'] . 'kb.';
                
// Проверка файла на наличие только одного расширения
                
if (count($ext) != 2)
                    
$error[] = $lng_forum['error_file_name'];
                
// Проверка допустимых расширений файлов
                
if (!in_array($ext[1], $ext_pic))
                    
$error[] = $lng_forum['error_file_ext'] . ':<br />' implode(', '$al_ext);
                
// Проверка на длину имени
                
if (strlen($fname) > 30)
                    
$error[] = $lng_forum['error_file_name_size'];
                
// Проверка на запрещенные символы
                
if (preg_match("/[^-9a-zA-Z-.]+/"$fname))
                    
$error[] = $lng_forum['error_file_symbols'];
                
// Проверка наличия файла с таким же именем
                
if (file_exists("photo/$id/$fname")) {
                    
unlink("photo/$id/$fname");
                }
                
// Окончательная обработка
                
if (!$error && $do_file) {
                    
// Для обычного браузера
                    
if ((move_uploaded_file($_FILES["fail"]["tmp_name"], "photo/$fname")) == true) {
                        @
chmod("$fname"0777);
                        @
chmod("photo/$fname"0777);
                        echo 
$lng_forum['file_uploaded'] . '<br/>';
                    } else {
                        
$error[] = $lng_forum['error_upload_error'];
                    }
                } elseif (
$do_file_mini) {
                    
// Для Opera Mini
                    
if (strlen($filebase64) > 0) {
                        
$FileName "photo/$fname";
                        
$filedata base64_decode($filebase64);
                        
$fid = @fopen($FileName"wb");
                        if (
$fid) {
                            if (
flock($fidLOCK_EX)) {
                                
fwrite($fid$filedata);
                                
flock($fidLOCK_UN);
                            }
                            
fclose($fid);
                        }
                        if (
file_exists($FileName) && filesize($FileName) == strlen($filedata)) {
                            echo 
$lng_stars['file_uploaded'] . '<br/>';
                        } else {
                            
$error[] = $lng_stars['error_upload_error'];
                        }
                    }
                }
                if (!
$error) {
                    
// Определяем тип файла
                    
$ext strtolower($ext[1]);
                    if (
in_array($ext$ext_win))
                        
$type 1;
                    elseif (
in_array($ext$ext_java))
                        
$type 2;
                    elseif (
in_array($ext$ext_sis))
                        
$type 3;
                    elseif (
in_array($ext$ext_doc))
                        
$type 4;
                    elseif (
in_array($ext$ext_pic))
                        
$type 5;
                    elseif (
in_array($ext$ext_arch))
                        
$type 6;
                    elseif (
in_array($ext$ext_video))
                        
$type 7;
                    elseif (
in_array($ext$ext_audio))
                        
$type 8;
                    else
                        
$type 9;

                } else {
                    echo 
functions::display_error($error'<a href="addfile.php?id=' $id '">' $lng['repeat'] . '</a>');
                }
            } else {
                echo 
$lng_stars['error_upload_error'] . '<br />';
            }
            
$pa mysql_query("SELECT `id` FROM `stars` WHERE `type` = '0' AND `id` = '" $cat['cid'] . "'");
            
$pa2 mysql_num_rows($pa);
            
$page ceil($pa2 $kmess);
            echo 
'<br/><a href="index.php?id=' $res['id'] . '&amp;page=' $page '">' $lng['continue'] . '</a><br/>';
        } else {
            
/*
            -----------------------------------------------------------------
            Форма выбора файла для выгрузки
            -----------------------------------------------------------------
            */
/*
---------------------------------
Верхнее меню навигации
---------------------------------
*/
echo '<div class="topmenu">
<div class="bmenu">'
 
. ($id ?  '<a href="index.php">' $lng_stars['stars'] . '</a>'
 
. ($cats3 != null ' - <a href="index.php?id=' $cats2['cid'] . '">' $cats3['name'] . '</a>' null)
 . (
$cats['cid'] != ' - <a href="index.php?id=' $res['cid'] . '">' $cats2['name'] . '</a>' null)
 . 
' - <b>' $res['name'] . '</b>' '<b>' $lng_stars['stars'] . '</b>')
 . 
' - ' $set['copyright'] . '</div></div>';
            echo 
'<div class="phdr"><b>' $lng_stars['add_foto'] . '</b></div>' .
                 
'<div class="gmenu"><form action="addfile.php?id=' $id '" method="post" enctype="multipart/form-data"><p>';
            if (
stristr($agn'Opera/8.01')) {
                echo 
'<input name="fail1" value =""/>&#160;<br/><a href="op:fileselect">' $lng_stars['select_file'] . '</a>';
            } else {
                echo 
'<input type="file" name="fail"/>';
            }
            echo 
'</p><p><input type="submit" name="submit" value="' $lng_stars['upload'] . '"/></p></form></div>' .
                 
'<div class="phdr">' $lng_stars['max_size'] . ': ' $set['flsz'] . 'kb.</div>';
        }
require(
'../incfiles/end.php');
?>
Онлайн: 0
Реклама