Файл: user/inc/avatar.php
Строк: 68
<?php
// ??? is too remake(add file info)
only_reg();
$set['title'] = 'Настройки аватара';
$back_link_set = true;
//загружаем класс для работы с изображениями
require_once  H . 'sys/inc/ImgType.class.php';
//список файлов о которых надо  не пропускать в оюбом случаи
$listIgnore = array('.php', '.phtml', '.php3', '.php4');
//ширина и высота
$wPic = $set['avatar_s'];
$hPic = $set['avatar_w'];
//как сохраняем
$savePic = '.png';
switch (empty($_GET['type_avatar']) ? false : $_GET['type_avatar']) {
default:
//upload pic
if (isset($_FILES['file'])) {
    $file_is = $_FILES['file']['name'];
    if ($_FILES['file']['name'] == null) {
        $_SESSION['message'] = lang('Не выбран файл ,или он поврежден');
        exit(header('Location: ?'));
    }
    //проверка игнор фалов // ??? nonsense!
    foreach ($listIgnore as $key) {
        if (preg_match("/$key$/i", $_FILES['file']['name'])) {
            exit(header('Location: ?'));
        }
    }
    if (is_file(H . 'files/avatars/' . $user['id'] . '.png')) {
        unlink(H . 'files/avatars/' . $user['id'] . '.png');
    }
   //класс для работы с файлом изображения
   $image = new ImgType();
   //сам файл
   $image->load($_FILES['file']['tmp_name']);
   //размеры
  //  $image->resize($wPic,$hPic);
   $image->resizeToWidth($wPic);
   //сохраняем под ...
   $image->save(H.'files/avatars/'. $user['id'] . $savePic);
    $_SESSION['message'] = lang('Аватар установлен');
    exit(header('Location: ?'));
}
err();
    echo "<form method='post' enctype='multipart/form-data' action=''>
        <table class='post'>
        <tr>
        <td class='p_m' rowspan='2'>";
        echo "<div class='avar_ank_set'>";
        avatar($user['id'], 200, 200, 0, null);
        echo '</div>';
        echo "</td>
                <td class='p_m'>
                    ".lang('Ваш текущий аватар')."
                </td>
            </tr>
            <tr>
                <td class='p_m'>
                    ".lang('Можно загружать картинки форматов').": GIF, JPG, PNG<br />
                </td>
            </tr>
            <tr>
                <td colspan='2' class='p_m'>
                    <input type='file' name='file' accept='image/*,image/gif,image/png,image/jpeg' />
                    <br /><input value='".lang('Заменить')."' type='submit' />
                </td>
        </tr>
        </table>
        </form>
        ";
echo "<div class='p_m'><a href='?type_avatar=import'>".lang('Импорт аватара с другого сайта')."</a></div>";
break;
case 'import':
//upload pic
            if (isset($_POST['imports'])) {
                $avatar_import = esc(stripcslashes(htmlspecialchars($_POST['import'])));
                foreach (array(
                    'jpg',
                    'jpeg',
                    'png',
                    'gif',
                    ) as $value) {
                    if (is_file(H . 'files/avatars/' . $user['id'] . '.' . $value)) {
                        unlink(H . 'files/avatars/' . $user['id'] . '.' . $value);
                    }
                }
                if (copyRemoteFile($avatar_import, H . 'sys/tmp/' . $user['id'] . $savePic)) {
                    $image = new ImgType;
                    $image->load(H . 'sys/tmp/' . $user['id'] . $savePic);//var_dump($image->image_type);exit;
                    if ($image->image_type) {
                        $image->resizeToWidth($wPic);
                         //сохраняем под ...
                        $image->save(H . 'files/avatars/' . $user['id'] . $savePic);
                        unlink(H . 'sys/tmp/' . $user['id'] . $savePic);
                        $_SESSION['message'] = lang('Аватар установлен');
                        exit(header('Location: ?type_avatar=import'));
                    } else {
                        unlink(H . 'sys/tmp/' . $user['id'] . $savePic);
                        $_SESSION['message'] = lang('Не верный тип файла!');
                        exit(header('Location: ?type_avatar=import'));
                    }
                } else {
                    $_SESSION['message'] = lang('Ошибка импорта');
                    exit(header('Location: ?type_avatar=import'));
                }
            }
  echo '<div class="p_m"><div class="avar_ank_set">';
  echo  avatar($user['id'], 200, 200, 0, null);
  echo '</div></div>';
echo '<div class="p_m">
        <form method="post" action="?type_avatar=import">
               ' . lang('Ссылка на картинку') . '<br />
               <input name="import" value="http://" type="text" accept="image/*,image/gif,image/png,image/jpeg,image/jpg" /><br />
        <input value="' . lang('Импортировать') . '" name="imports" type="submit"  accept="image/*,image/gif,image/png,image/jpeg,image/jpg"/>
    </form>
</div>';
echo '<a href="?" title="' . lang('Обычная загрузка') . '"><div class="p_m"> ' . lang('Обычная загрузка') . ' </div></a>';
break;
}