<?php
include ('inc/base.php');
include ('inc/functions.php');
include ('inc/user.php');
$title = 'Аватары';
include ('inc/header.php');
if(!$user) {
header('location: /');
exit();
}
function can_upload($file){
$max_size = 64 * 1024;
if($file['name'] == '') return 'Вы не выбрали аватар.';
if($file['size'] > $max_size) return 'Аватар слишком много весит.';
$getMime = explode('.', $file['name']);
$mime = strtolower(end($getMime));
$types = array('png');
if(!in_array($mime, $types)) return 'Недопустимый тип файла. Разрешены картинки в формате .png';
return true;
}
function make_upload($file){
global $name;
$name = mt_rand(0, 10000) . $file['name']; copy($file['tmp_name'], 'img/' . $name);
copy($file['tmp_name'], 'style/src/avatars/' . $name);
}
if(isset($_FILES['file'])) {
$check = can_upload($_FILES['file']);
if($check === true){
make_upload($_FILES['file']);
mysql_query("update `accounts` set `avatar` = '".$name."' where `id` = '".$user['id']."'");
echo "<div class='main center'>Аватар $name успешно загружен!</div>";
} else {
echo "<div class='main center'>$check</div>";
}
}
if(isset($_GET['download'])) {
echo '<div class="main center"><form method="post" action="?" enctype="multipart/form-data"> <input type="file" class="text" name="file"> <br> <input type="submit" class="input_send value="Загрузить"> </form></div>';
include ('inc/footer.php');
exit();
}
$id = num($_GET['id']);
if($id and $id >= '1' and $id <= '6' and $id != $user['avatar']) {
$ava = ''.$id.'.png';
mysql_query("update `accounts` set `avatar` = '".$ava."' where `id` = '".$user['id']."'");
echo '<div class="main center">Аватар установлен!</div>';
echo '<a href="/profile.php?id='.$user['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
echo '<div class="main center">Вы можете <a href="?download" class="a2">загрузить</a> свой аватар бесплатно или выбрать любой из существующих!</div><div class="new-line"></div> <div class="main center"><a href="?id=1" class="none"><img src="/style/src/avatars/1.png"></a><div class="margin"></div><a href="?id=2" class="none"><img src="/style/src/avatars/2.png"></a><div class="margin"></div><a href="?id=3" class="none"><img src="/style/src/avatars/3.png"></a><div class="new-line"></div><a href="?id=4" class="none"><img src="/style/src/avatars/4.png"></a><div class="margin"></div><a href="?id=5" class="none"><img src="/style/src/avatars/5.png"></a><div class="margin"></div><a href="?id=6" class="none"><img src="/style/src/avatars/6.png"></a><div class="new-line"></div></div>';
include ('inc/footer.php');
?>