<?
echo "<div class='app-block'>";
if (DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `blog_files` WHERE `id_user` = '".$user['id']."' AND `time` = '0'") >= 5)
{
?>
    <div class="list _gray _font-s _center">Вы прикрепили максимальное количество файлов!</div>
<?
} else {
    if (isset($_POST['send']))
    {
        if (isset($_FILES['filik_ob']) && isset($_FILES['filik_ob']['tmp_name']))
        {
            if ((preg_match('#\.jpe?g$#i',$_FILES['filik_ob']['name']) && $imgc=@imagecreatefromjpeg($_FILES['filik_ob']['tmp_name'])) || (preg_match('#\.gif$#i',$_FILES['filik_ob']['name']) && $imgc=@imagecreatefromgif($_FILES['filik_ob']['tmp_name'])) || (preg_match('#\.png$#i',$_FILES['filik_ob']['name']) && $imgc=@imagecreatefrompng($_FILES['filik_ob']['tmp_name'])))
            {
                DB :: $pdo -> query("INSERT INTO `blog_files` (`id_user`) VALUES (?);", array($user['id']));
                $last_id = DB :: $pdo -> lastInsertId();
                $screen = imagecreatetruecolor(150, 150);
                imagecopyresampled($screen, $imgc, 0, 0, 0, 0, 150, 150, imagesx($imgc), imagesy($imgc));
                imagejpeg($screen,"".FILES_PATH."/blog_files/".$last_id."_m.jpg",100);
                chmod("".FILES_PATH."/blog_files/".$last_id."_m.jpg",0777);
                imagejpeg($imgc,"".FILES_PATH."/blog_files/".$last_id.".jpg",100);
                chmod("".FILES_PATH."/blog_files/".$last_id.".jpg",0777);
                header("Location: /blog/?id=".$ank['id']."");
                exit;
            } else {
                $error = 'Ошибка при выгрузке файла!';
            }
        } else {
            $error = 'Виберите файл!';
        }
    }
    if (isset($error))
    {
    ?>
        <div class="list _gray _font-s _center"><?echo $error;?></div>
    <?
    }
    ?>
    <div class="list">
        <form method="post" enctype="multipart/form-data" action="/blog/?id=<?echo $ank['id'];?>&add_files">
            <div class="list_blog16">
                Файл:<br />
                <input name="filik_ob" type="file" /><br />
            </div>
            <div class="list_blog16">
                <input class="main-btn" type="submit" name="send" value="Загрузить фото" />
            </div>
        </form>
    </div>
    <?
}
echo system :: touch("/blog/?id=".$ank['id']."", system :: icon("arr-l")."Назад");
require (CORE."foot.php");
?>