View file avatar/index.php

File size: 4.52Kb
<?
/*
=============================================
Движок: SHCMS Engine
=============================================
Название файла: Установка аватара
=============================================
Official website: http://shcms.ru
=============================================
*/
define('SHCMS', true);
include_once'../system/inc/basic_settings.php';
$shcmsengine['title'] = 'Загрузка аватара';
include_once'../template/head.php';
registrat();



  if(isset($_POST['submit']))
  {
     $submit = $_POST['submit'];
  }
  
if(isset($submit))
{

     $file_avatar = '../avatar/files/'; // папка с аватарами


        if(!empty($_FILES['image']))
        {
    if($_FILES['image']['error'])
    {
     echo '<div class="errors">Ошибка при выгрузке</div>';
     header("Refresh: 1; url=?");
     include_once'../template/foot.php';
     exit();
    }
    if(!$_FILES['image']['size'])
    {
     echo '<div class="errors">Содержимое файла пустое</div>';
     header("Refresh: 1; url=?");
     include_once'../template/foot.php';
     exit();
    }
    if(!preg_match('#\.jpe?g$#ui', $_FILES ['image']['name']) and !preg_match('#\.gif$#ui',$_FILES['image']['name']))
    {
     echo '<div class="errors">Неверное содержание файла</div>';
     header("Refresh: 1; url=?");
     include_once'../template/foot.php';
     exit();
    }
    
	if(!$img = @imagecreatefromjpeg($_FILES ['image'] ['tmp_name']) and !$img = imagecreatefromgif($_FILES['image']['tmp_name']))
    {
     echo '<div class="errors">Файл не является изображением JPEG или GIF</div>';
     header("Refresh: 1; url=?");
     include_once'../template/foot.php';
     exit();
    }
    
	if((@imagesx($img) < 130))
    {
     echo '<div class="errors">Ширина изобожения должно быть больше 130px</div>';
     header("Refresh: 1; url=?");
     include_once'../template/foot.php';
     exit();
    }
	
    if((@imagesy($img) < 130))
    {
     echo '<div class="errors">Ширина изобожения должно быть больше 130px</div>';
     header("Refresh: 1; url=?");
     include_once'../template/foot.php';
     exit();
    }
        }
		
     $handle = new upload($_FILES['image']);
    if ($handle->uploaded) 
	{
     $handle->file_new_name_body = $user_id;
     $handle->allowed = array('image/jpeg', 'image/gif');
     $handle->file_overwrite = true;
     $handle->image_convert = 'jpg';
     $handle->image_resize = true;
	if($_POST['amount'] == 1)
    {
     $handle->image_y = 130; 
     $handle->image_x = 130; 
    }elseif($_POST['amount'] == 2)
    {		       
     $handle->image_y = 180; 
     $handle->image_x = 180;
    }elseif($_POST['amount'] == 3)
    {
     $handle->image_y = 220; 
	 $handle->image_x = 220;
    }elseif($_POST['amount'] == 4)
    {	
     $handle->image_y = 300; 
     $handle->image_x = 300;
    }	
	 $handle->process("$file_avatar");
    if ($handle->processed) {
     echo '<div class="actshcms">Аватар успешно установлен</div>';
    }
    else {
     echo errors($handle->error);
    }
     $handle->clean();
    }
}

    if(is_file('../avatar/files/'.$user_id.'.jpg')){
        echo '<img class="image_avatar" src="../avatar/files/'.$user_id.'.jpg"/><br/>';
    }
        $images_amount = array(1=>'130x130', 
		                       2=>'180x180',
							   3=>'220x220',
							   4=>'300x300');
						
        echo 'Файл аватара(.gif и .jpg)<br/>';
        echo '<form enctype="multipart/form-data" action="?'.$conservation.'" method="post">';
        echo "<input accept='image/*,image/gif,image/jpeg'  type='file' name='image'/>";
        echo '<br/>Выбор размера аватара:<br/><select name="amount">';
        echo "<option selected>{$images_amount[$_POST[amount]]}";
        echo '<option value="1">130x130</option>';
        echo '<option value="2">180x180</option>';
        echo '<option value="3">220x220</option>';
        echo '<option value="4">300x300</option>';
        echo '</option></select>';
    if(!is_file('../avatar/files/'.$user_id.'.jpg'))
    {
        echo '<br/><input type="submit" value="Установить" name="submit"/>';
	}
    else
	{
        echo '<br/><input type="submit" value="Заменить" name="submit"/>';
	}
        echo '</form>';
		
		
include_once'../template/foot.php';
?>