View file ajax/newModal/mail/upload.php

File size: 2.08Kb
<?
include_once $_SERVER['DOCUMENT_ROOT'] . '/sys/inc/home.php';
include_once H.'sys/inc/start.php'; 
include_once H.'sys/inc/compress.php';
include_once H.'sys/inc/sess.php';
include_once H.'sys/inc/settings.php';
include_once H.'sys/inc/db_connect.php';
include_once H.'sys/inc/ipua.php'; 
include_once H.'sys/inc/fnc.php';
include_once H.'sys/inc/user.php';

$ank = get_user($_GET['id']);

if (!$user['id'] || !$ank)
{
	$result = "error";
	exit;	
}

if (isset($_FILES['uploadfile']))
{
	$name = my_esc(preg_replace('#\.[^\.]*$#', NULL, $_FILES['uploadfile']['name']));
	$ras = my_esc(strtolower(preg_replace('#^.*\.#', NULL, $_FILES['uploadfile']['name'])));
	
	mysql_query("INSERT INTO `mail_files` (`id_kont`, `name`, `ras`) VALUES ('$user[id]', '$name', '$ras')");
	$ID = mysql_insert_id();
	
	if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], H.'sys/mail/files/' . $ID . '.dat')) 
	{
		if ($imgc = @imagecreatefromstring(file_get_contents(H.'sys/mail/files/' . $ID . '.dat')))
		{
			$img_x = imagesx($imgc);
			$img_y = imagesy($imgc);
			
			if ($img_x == $img_y)
			{
				$dstW = 220; // ширина
				$dstH = 220; // высота 
			}	
				elseif ($img_x > $img_y)
			{		
				$prop = $img_x / $img_y;
				$dstW = 220;
				$dstH = ceil($dstW/$prop);
			}	
			else
			{
				$prop = $img_y/$img_x;
				$dstH = 220;
				$dstW = ceil($dstH/$prop);
			}
		
		
		
			$screen = imagecreatetruecolor($dstW, $dstH);
			imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
			imagedestroy($imgc);
			//$screen=img_copyright($screen); // наложение копирайта
			imagegif($screen,H."sys/mail/screen/$ID.png");
			@chmod(H.'sys/mail/screen/' . $ID . '.png', 0666);
			imagedestroy($screen);
		
		}
		
		@chmod(H.'sys/mail/files/' . $ID . '.dat', 0666);
		$succes = true;
		$result = "success"; 
	} 
	else 
	{
		// Если файл не был загружен, удаляем запись..
		mysql_query("DELETE FROM `mail_files` WHERE `id` = '" . $ID . "'");
		$result = "error";
	}
}

echo $result;
?>