<?php

if (!empty($_FILES))
{
	require_once HOME.'/toolkit/AcImage.php';
	AcImage::setTransparency(true);
function upload_photo($file) {
global $user_id, $id;
	if(AcImage::isFileExists($_FILES[$file]['tmp_name'])) {} else {$err = lang('Файл не существует!','Файл не існує!');}
	if($err == false && AcImage::isFileImage($_FILES[$file]['tmp_name']))
	{
		$file_name = time().'.jpg';
		copy($_FILES[$file]['tmp_name'], HOME.'/files/doc/'.$user_id.'/'.$file_name);
		///
		$savePath = HOME.'/files/doc/'.$user_id.'/mini/'.$file_name;
		$filePath = $_FILES[$file]['tmp_name'];
		$image = AcImage::createImage($filePath);
		$image
		->cropCenter('4pr', '4pr')
		->resizeByWidth(150)
		->save($savePath);
		$savePath2 = HOME.'/files/doc/'.$user_id.'/icons/'.$file_name;
		$filePath2 = HOME.'/files/doc/'.$user_id.'/mini/'.$file_name;
		$image2 = AcImage::createImage($filePath2);
		$image2
		->cropCenter('4pr', '4pr')
		->resizeByWidth(50)
		->save($savePath2);
		$savePath3 = HOME.'/files/doc/'.$user_id.'/preview/'.$file_name;
		$filePath3 = HOME.'/files/doc/'.$user_id.'/'.$file_name;
		$image3 = AcImage::createImage($filePath3);
		$image3
		->resizeByWidth(600)
		->save($savePath3);

		mysql_query("UPDATE `users` SET `count_doc`=`count_doc` + '1' WHERE `id` = '".$user_id."'");
		mysql_query("UPDATE `doc_papka` SET count_doc=count_doc + 1, `uptime` = '".time()."', `cover` = '".$file_name."' WHERE `id` = '".$id."'");
		mysql_query("INSERT INTO `doc_file` SET `name` = '".$file_name."', `user_id` = '".$user_id."', `time` = '".time()."', `aid` = '".$id."'");
	}
}

if (!empty($_FILES['file1'])) upload_photo('file1');


if ($ajax_query == true) exit;

}

?>
