View file xmyx.ru/albums/act/add.php

File size: 8.86Kb
<?php defined('ACCESS') OR die('No direct script access...');

/*
* Author - Tw1nGo
* VK - https://vk.com/tw1ngo93
*/

if (isset($_GET['id']))
{
    $album = mysql_fetch_assoc(mysql_query("SELECT * FROM `photos` WHERE `id` = '".abs(intval($_GET['id']))."' LIMIT 1"));
    $ank = mysql_fetch_assoc(mysql_query("SELECT `id`,`nick` FROM `user` WHERE `id` = '".$album['id_user']."' LIMIT 1"));
}

if (!isset($_GET['id']) || !isset($album) || $album['id'] <= 0 || $user['id'] != $ank['id']){
	header("Location: /photos/?id=".$ank['id']."");
	exit;
}


// Загрузка фото
if (isset($user) && $user['id'] == $ank['id'] && isset($_POST['cfms'])){

if (isset($_FILES['file1'])){

if ($imgc = @imagecreatefromstring(file_get_contents($_FILES['file1']['tmp_name'])))
{

$name = esc(stripcslashes(htmlspecialchars(preg_replace('#\.[^\.]*$#i', NULL, $_FILES['file1']['name'])))); 
   
if (!preg_match("#^([A-zА-я0-9\-\_\ ])+$#ui",$name))$name = 'Images';

$name = my_esc($name);

$img_x = imagesx($imgc);
$img_y = imagesy($imgc);
if ($img_x > 4048 || $img_y > 4048)
   $err = 'Изображение слишком большое, загружайте файлы не больше 4048*4048.';

if ($img_x < 150 || $img_y < 150)
   $err = 'Изображение слишком маленькое, загружайте файлы не меньше 150x150, у вас '.$img_x.'x'.$img_y.'.';

    $sizeq = (int) $_FILES['file1']['size'];
    $hash = md5($sizeq);

if (!isset($err))
{

mysql_query("INSERT INTO `photos_user` (`id_album`, `name`, `ras`, `type`, `msg`, `id_user`, `metka`, `time`, `hash`) values ('$album[id]', '$name', 'jpg', 'image/jpeg', '$msg', '$user[id]', '$adult', '$time', '$hash')");

$id_foto1 = mysql_insert_id();
	
imagejpeg($imgc,H."files/photos/original/".$id_foto1."".$hash.".jpg",90);
@chmod(H."files/photos/original/".$id_foto1."".$hash.".jpg",0777);
imagedestroy($imgc);

// 50x50
crop(H."files/photos/original/".$id_foto1."".$hash.".jpg", H."files/photos/size50/".$id_foto1."".$hash.".tmp.jpg");
resize(H."files/photos/size50/".$id_foto1."".$hash.".tmp.jpg", H."files/photos/size50/".$id_foto1."".$hash.".jpg", 50, 50);
@chmod(H."files/photos/size50/".$id_foto1."".$hash.".jpg",0777);
@unlink(H."files/photos/size50/".$id_foto1."".$hash.".tmp.jpg");

// 100x100
crop(H."files/photos/original/".$id_foto1."".$hash.".jpg", H."files/photos/size100/".$id_foto1."".$hash.".tmp.jpg");
resize(H."files/photos/size100/".$id_foto1."".$hash.".tmp.jpg", H."files/photos/size100/".$id_foto1."".$hash.".jpg", 100, 100);
@chmod(H."files/photos/size100/".$id_foto1."".$hash.".jpg",0777);
@unlink(H."files/photos/size100/".$id_foto1."".$hash.".tmp.jpg");

// 200x200
crop(H."files/photos/original/".$id_foto1."".$hash.".jpg", H."files/photos/size200/".$id_foto1."".$hash.".tmp.jpg");
resize(H."files/photos/size200/".$id_foto1."".$hash.".tmp.jpg", H."files/photos/size200/".$id_foto1."".$hash.".jpg", 200, 200);
@chmod(H."files/photos/size200/".$id_foto1."".$hash.".jpg",0777);
@unlink(H."files/photos/size200/".$id_foto1."".$hash.".tmp.jpg");

}
}
//else $err = 'Выбранный Вами формат изображения не поддерживается1';
}

## Файл 2
if(isset($_FILES['file2'])){

if ($imgc = @imagecreatefromstring(file_get_contents($_FILES['file2']['tmp_name'])))
{

$name = esc(stripcslashes(htmlspecialchars(preg_replace('#\.[^\.]*$#i', NULL, $_FILES['file2']['name'])))); 
   
if (!preg_match("#^([A-zА-я0-9\-\_\ ])+$#ui",$name))$name = 'Images';

$name = my_esc($name);

$img_x = imagesx($imgc);
$img_y = imagesy($imgc);
if ($img_x > 4048 || $img_y > 4048)
   $err = 'Изображение слишком большое, загружайте файлы не больше 4048*4048.';

if ($img_x < 50 || $img_y < 50)
   $err = 'Изображение слишком маленькое, загружайте файлы не меньше 150x150, у вас '.$img_x.'x'.$img_y.'.';

    $sizeq = (int) $_FILES['file2']['size'];
    $hash = md5($sizeq);

if (!isset($err))
{

mysql_query("INSERT INTO `photos_user` (`id_album`, `name`, `ras`, `type`, `id_user`, `time`, `hash`) values ('$album[id]', '$name', 'jpg', 'image/jpeg', '$user[id]', '$time', '$hash')");

$id_foto = mysql_insert_id();
	
imagejpeg($imgc,H."files/photos/original/".$id_foto."".$hash.".jpg",90);
@chmod(H."files/photos/original/".$id_foto."".$hash.".jpg",0777);
imagedestroy($imgc);

// 50x50
crop(H."files/photos/original/".$id_foto."".$hash.".jpg", H."files/photos/size50/".$id_foto."".$hash.".tmp.jpg");
resize(H."files/photos/size50/".$id_foto."".$hash.".tmp.jpg", H."files/photos/size50/".$id_foto."".$hash.".jpg", 50, 50);
@chmod(H."files/photos/size50/".$id_foto."".$hash.".jpg",0777);
@unlink(H."files/photos/size50/".$id_foto."".$hash.".tmp.jpg");

// 100x100
crop(H."files/photos/original/".$id_foto."".$hash.".jpg", H."files/photos/size100/".$id_foto."".$hash.".tmp.jpg");
resize(H."files/photos/size100/".$id_foto."".$hash.".tmp.jpg", H."files/photos/size100/".$id_foto."".$hash.".jpg", 100, 100);
@chmod(H."files/photos/size100/".$id_foto."".$hash.".jpg",0777);
@unlink(H."files/photos/size100/".$id_foto."".$hash.".tmp.jpg");

// 200x200
crop(H."files/photos/original/".$id_foto."".$hash.".jpg", H."files/photos/size200/".$id_foto."".$hash.".tmp.jpg");
resize(H."files/photos/size200/".$id_foto."".$hash.".tmp.jpg", H."files/photos/size200/".$id_foto."".$hash.".jpg", 200, 200);
@chmod(H."files/photos/size200/".$id_foto."".$hash.".jpg",0777);
@unlink(H."files/photos/size200/".$id_foto."".$hash.".tmp.jpg");

}
}
//else $err = 'Выбранный Вами формат изображения не поддерживается2';
}

## Файл 3
if(isset($_FILES['file3'])){

if ($imgc = @imagecreatefromstring(file_get_contents($_FILES['file3']['tmp_name'])))
{

$name = esc(stripcslashes(htmlspecialchars(preg_replace('#\.[^\.]*$#i', NULL, $_FILES['file3']['name'])))); 
   
if (!preg_match("#^([A-zА-я0-9\-\_\ ])+$#ui",$name))$name = 'Images';

$name = my_esc($name);

$img_x = imagesx($imgc);
$img_y = imagesy($imgc);
if ($img_x > 4048 || $img_y > 4048)
   $err = 'Изображение слишком большое, загружайте файлы не больше 4048*4048.';

if ($img_x < 50 || $img_y < 50)
   $err = 'Изображение слишком маленькое, загружайте файлы не меньше 150x150, у вас '.$img_x.'x'.$img_y.'.';

    $sizeq = (int) $_FILES['file3']['size'];
    $hash = md5($sizeq);

if (!isset($err))
{

mysql_query("INSERT INTO `photos_user` (`id_album`, `name`, `ras`, `type`, `id_user`, `time`, `hash`) values ('$album[id]', '$name', 'jpg', 'image/jpeg', '$user[id]', '$time', '$hash')");

$id_foto = mysql_insert_id();
	
imagejpeg($imgc,H."files/photos/original/".$id_foto."".$hash.".jpg",90);
@chmod(H."files/photos/original/".$id_foto."".$hash.".jpg",0777);
imagedestroy($imgc);

// 50x50
crop(H."files/photos/original/".$id_foto."".$hash.".jpg", H."files/photos/size50/".$id_foto."".$hash.".tmp.jpg");
resize(H."files/photos/size50/".$id_foto."".$hash.".tmp.jpg", H."files/photos/size50/".$id_foto."".$hash.".jpg", 50, 50);
@chmod(H."files/photos/size50/".$id_foto."".$hash.".jpg",0777);
@unlink(H."files/photos/size50/".$id_foto."".$hash.".tmp.jpg");

// 100x100
crop(H."files/photos/original/".$id_foto."".$hash.".jpg", H."files/photos/size100/".$id_foto."".$hash.".tmp.jpg");
resize(H."files/photos/size100/".$id_foto."".$hash.".tmp.jpg", H."files/photos/size100/".$id_foto."".$hash.".jpg", 100, 100);
@chmod(H."files/photos/size100/".$id_foto."".$hash.".jpg",0777);
@unlink(H."files/photos/size100/".$id_foto."".$hash.".tmp.jpg");

// 200x200
crop(H."files/photos/original/".$id_foto."".$hash.".jpg", H."files/photos/size200/".$id_foto."".$hash.".tmp.jpg");
resize(H."files/photos/size200/".$id_foto."".$hash.".tmp.jpg", H."files/photos/size200/".$id_foto."".$hash.".jpg", 200, 200);
@chmod(H."files/photos/size200/".$id_foto."".$hash.".jpg",0777);
@unlink(H."files/photos/size200/".$id_foto."".$hash.".tmp.jpg");

}
}

}
header("Location: ?act=album&id=".$album['id']."");
exit;
}



$set['title'] = ''.text($album['name']).'';
include_once '../sys/inc/thead.php';
shapka_VK(true, '?act=album&id='.$album['id'].'', 'Альбом');
err();

?>
<div class="pcont bl_cont">
  
  <h4 class="sub_header"><?= text($album['name'])?></h4>
  <div class="form_item upload_form">
    <form action="?act=add&id=<?= $album['id']?>" method="post" enctype="multipart/form-data">
      <div class="upload_row">
        <input class="upload_input" accept="image/*,image/jpeg" name="file1" type="file">
      </div>
      <div class="upload_row">
        <input class="upload_input" accept="image/*,image/jpeg" name="file2" type="file">
      </div>
      <div class="upload_row">
        <input class="upload_input" accept="image/*,image/jpeg" name="file3" type="file">
      </div>
      <div class="upload_row">
        <input class="button" value="Загрузить фотографии" name="cfms" type="submit">
      </div>
    </form>
  </div>
</div>
<?