<?
if (DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `blog_files` WHERE `id_user` = '".$user['id']."' AND `id_blog` = '".$note['id']."'") >= 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`, `id_blog`, `time`) VALUES (?, ?, ?);", array($user['id'], $note['id'], time()));
$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/?note=".$note['id']."&edit");
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/?note=<?echo $note['id'];?>&edit&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/?note=".$note['id']."&edit", system :: icon("arr-l")."Назад");
require (CORE."foot.php");
?>