Файл: user/settings/avatar.php
Строк: 109
<?php
require_once '../../sys/inc/start.php';
require_once '../../sys/inc/compress.php';
require_once '../../sys/inc/sess.php';
require_once '../../sys/inc/settings.php';
require_once '../../sys/inc/db_connect.php';
require_once '../../sys/inc/ipua.php';
require_once '../../sys/inc/fnc.php';
require_once '../../sys/inc/user.php';
only_reg();
$set['title'] = 'Мой аватар';
require_once '../../sys/inc/thead.php';
title();
aut();
err();
if (isset($_GET['act']) && $_GET['act'] == 'delete' && isset($_GET['ok'])) {
@unlink(H . "sys/avatar/$user[id].jpg");
@unlink(H . "sys/avatar/$user[id].gif");
@unlink(H . "sys/avatar/$user[id].png");
msg('Аватар успешно удален');
require_once '../../sys/inc/tfoot.php';
exit;
}
if (isset($_FILES['file'])) {
if (preg_match('#.jpe?g$#i', $_FILES['file']['name']) && $imgc = imagecreatefromjpeg($_FILES['file']['tmp_name'])) {
if (imagesx($imgc) > 500 || imagesy($imgc) > 500) {
$img_x = imagesx($imgc);
$img_y = imagesy($imgc);
if ($img_x == $img_y) {
$dstW = 500; #ширина
$dstH = 500; #высота
} elseif ($img_x > $img_y) {
$prop = $img_x / $img_y;
$dstW = 500;
$dstH = ceil($dstW / $prop);
} else {
$prop = $img_y / $img_x;
$dstH = 500;
$dstW = ceil($dstH / $prop);
}
$screen = imagecreatetruecolor($dstW, $dstH);
imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
imagedestroy($imgc);
$avs = glob(H . "sys/avatar/$user[id].*");
if ($avs) {
foreach ($avs as $value) {
chmod($value, 0777);
@unlink($value);
}
}
imagejpeg($screen, H . "sys/avatar/$user[id].jpg", 500);
chmod(H . "sys/avatar/$user[id].jpg", 0777);
imagedestroy($screen);
} else {
copy($_FILES['file']['tmp_name'], H . "sys/avatar/$user[id].jpg");
}
msg("Аватар успешно установлен");
mysql_query("DELETE FROM `avatar_comments` WHERE `avatar_id`= '$user[id]' ");
mysql_query("DELETE FROM `avatar_like` WHERE `id_komm`= '$user[id]' ");
} elseif (preg_match('#.gif$#i', $_FILES['file']['name']) && $imgc = imagecreatefromgif($_FILES['file']['tmp_name'])) {
$screen = gif_resize(fread(fopen($_FILES['file']['tmp_name'], "rb"), filesize($_FILES['file']['tmp_name'])), 500, 500);
$avs = glob(H . "sys/avatar/$user[id].*");
if ($avs) {
foreach ($avs as $value) {
chmod($value, 0777);
@unlink($value);
}
}
file_put_contents(H . "sys/avatar/$user[id].gif", $screen);
chmod(H . "sys/avatar/$user[id].gif", 0777);
msg("Аватар успешно установлен");
mysql_query("DELETE FROM `avatar_comments` WHERE `avatar_id`= '$user[id]' ");
mysql_query("DELETE FROM `avatar_like` WHERE `id_komm`= '$user[id]' ");
} elseif (preg_match('#.png$#i', $_FILES['file']['name']) && $imgc = imagecreatefrompng($_FILES['file']['tmp_name'])) {
if (imagesx($imgc) > 500 || imagesy($imgc) > 500) {
$img_x = imagesx($imgc);
$img_y = imagesy($imgc);
if ($img_x == $img_y) {
$dstW = 500; #ширина
$dstH = 500; #высота
} elseif ($img_x > $img_y) {
$prop = $img_x / $img_y;
$dstW = 500;
$dstH = ceil($dstW / $prop);
} else {
$prop = $img_y / $img_x;
$dstH = 500;
$dstW = ceil($dstH / $prop);
}
$screen = ImageCreate($dstW, $dstH);
imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
imagedestroy($imgc);
$avs = glob(H . "sys/avatar/$user[id].*");
if ($avs) {
foreach ($avs as $value) {
chmod($value, 0777);
@unlink($value);
}
}
imagepng($screen, H . "sys/avatar/$user[id].png");
chmod(H . "sys/avatar/$user[id].png", 0777);
imagedestroy($screen);
} else {
copy($_FILES['file']['tmp_name'], H . "sys/avatar/$user[id].png");
}
msg("Аватар успешно установлен");
mysql_query("DELETE FROM `avatar_comments` WHERE `avatar_id`= '$user[id]' ");
mysql_query("DELETE FROM `avatar_like` WHERE `id_komm`= '$user[id]' ");
} else {
$err = 'Неверный формат файла';
}
}
if (isset($_GET['act']) && $_GET['act'] == 'delete') {
echo "<form method = 'post' class = 'razd' action = '?act=delete&ok'>n";
echo "Подтвердите удаление аватара<br />";
echo "<div class = 'right' id = 'hide'>";
echo "<a href = '?' title = 'Отмена'><img src = '/style/icons/cross.png' /></a>";
echo "</div>";
echo "<button class = 'btn'>";
echo "<img src = '/style/icons/tick.png' /> Удалить";
echo "</button></form>";
}
$ava = avatar_path($user['id']);
if (isset($_POST['delete'])) {
header("Location: ?act=delete" . SID);
exit;
}
if ($ava) {
echo "<div class = 'blok'>Ваш текущий аватар</div>";
} else {
echo "<div class = 'blok'>Загрузка аватара</div>";
}
echo "<form method = 'post' class = 'razd' enctype = 'multipart/form-data' action = '?$passgen'>n";
if ($ava) {
avatar($user['id'], '300');
echo "<div class = 'hr'></div>";
}
echo "Можно загружать изображения форматов: GIF, JPG, PNG<br/>";
echo "Качественное преобразование GIF-анимации не гарантируется<br/>";
echo "<div class = 'hr'></div>";
echo "<input type = 'file' name = 'file' accept = 'image/*,image/gif,image/png,image/jpeg' /><br/>";
if ($ava) {
echo "<button class = 'action'>";
echo "<span class = 'label'>Заменить</span>";
echo "</button>";
echo "<button class = 'action red' name = 'delete'>";
echo "<span class = 'label'>Удалить текущий</span>";
echo "</button>";
} else {
echo "<button class = 'action'>";
echo "<span class = 'label'>Загрузить</span>";
echo "</button>";
}
echo "</form>";
if (isset($_SESSION['refer']) && $_SESSION['refer'] != NULL && otkuda($_SESSION['refer'])) {
echo "<div class = 'razd'>";
echo img('left.png') . " <a href = '$_SESSION[refer]'>" . otkuda($_SESSION['refer']) . "</a>";
echo "</div>";
}
echo "<div class = 'razd'>";
echo img('left.png') . " <a href = '/umenu.php'>Кабинет</a>";
echo "</div>";
require_once '../../sys/inc/tfoot.php';