Файл: app/user/avatar.php
Строк: 45
<?php
Core::only('user');
$smarty->header('Аватар');
if (filter_has_var(INPUT_GET, 'delete') && file_exists(ROOT . 'upload/photo/' . $user['id'] . '.png'))
{
unlink(ROOT . 'upload/photo/' . $user['id'] . '.png');
unlink(ROOT . 'upload/photo/' . $user['id'] . '_small.png');
Core::go('?');
}
if (filter_has_var(INPUT_POST, 'submit'))
{
$file = new Upload($_FILES['photo']);
$all_ext = array('jpg', 'jpeg', 'gif', 'png', 'JPG', 'JPEG', 'GIF', 'PNG');
$ext = explode(".", $_FILES['photo']['name']);
if (!in_array($ext[1], $all_ext))
{
$error = 'Неверный формат.';
}
elseif (empty($error) && $file->uploaded)
{
$file->file_new_name_body = $user['id'];
$file->allowed = array('image/jpeg', 'image/gif', 'image/png');
$file->file_max_size = 1024 * 3000;
$file->file_overwrite = true;
$file->image_ratio_y = true;
$file->image_convert = 'png';
$file->process(ROOT . '/upload/photo/');
$file->processed;
$file->file_new_name_body = $user['id'] . '_small';
$file->allowed = array('image/jpeg', 'image/gif', 'image/png');
$file->file_max_size = 1024 * 3000;
$file->file_overwrite = true;
$file->image_resize = true;
$file->image_x = 50;
$file->image_ratio_y = true;
$file->image_convert = 'png';
$file->process(ROOT . '/upload/photo/');
$file->processed;
}
}
Core::show('error');
if (file_exists(ROOT . '/upload/photo/' . $user['id'] . '.png'))
{
$listing[] = [
'title' => '<img src="/upload/photo/' . $user['id'] . '_small.png">',
'div' => 'menu'
];
$listing[] = [
'title' => Lang::word('Удалить'),
'url' => '?delete',
'div' => 'block',
'icon' => 'delete'
];
$smarty->assign('listing', $listing);
$smarty->display('listing.tpl');
}
$elements[] = [
'type' => 'file',
'title' => Lang::word('Фотография'),
'br' => 1,
'info' => [
'name' => 'photo'
]
];
$elements[] = [
'type' => 'submit',
'info' => [
'name' => 'submit',
'value' => Lang::word('Сохранить')
]
];
$smarty->assign([
'files' => 1,
'method' => 'POST',
'action' => '?',
'el' => $elements
]);
$smarty->display('form.tpl');
$smarty->footer();