if(isset($_POST["load"])) { //var_dump($_FILES); //exit; /* type - 1. text 2. images 3. sound 4. video 5. other */ if(is_uploaded_file($_FILES["file"]["tmp_name"])) { if(preg_match("#\.(jpg|jpeg|png|gif|rar|zip|exe|iso|dll|torrent|mp3|wav|3gp|mkv|mp4|avi)$#i", $_FILES["file"]["name"], $imgtype)) { if(!file_exists("../upload/news/")) {mkdir("../upload/news/", 0700);} if(!file_exists("../upload/news/$_GET[id]/")) {mkdir("../upload/news/$_GET[id]/", 0700);} $format = $imgtype[0]; function g_name_random($format) { $arr = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"); $pass = ""; for($i = 0; $i < rand(10, 30); $i++) {$pass .= $arr[rand(0, 35)];} $pass .= $format; if(file_exists("../upload/news/$_GET[id]/".$pass)) {return g_name_random($format);} return $pass; } $filenumb = 1; $filetype = 5; $filesize = $_FILES["file"]["size"]; $filename = g_name_random($format); $fileoname = $_FILES["file"]["name"]; if($format == ".jpg" || $format == ".jpeg" || $format == ".png" || $format == ".gif") {$filetype = 2;} elseif($format == ".mp3" || $format == ".wav") {$filetype = 3;} elseif($format == ".3gp" || $format == ".mkv" || $format == ".mp4" || $format == ".mp4" || $format == ".avi") {$filetype = 4;} $connect = mysql_query("SELECT `number` FROM `news_contents` WHERE `section` = '$_GET[id]' ORDER BY `number` DESC LIMIT 1"); $files = mysql_fetch_object($connect); if($files) {$filenumb = $files->number+1;} if($filetype == 2) { if($filesize < (2*1048576)) { if($format == ".jpg" || $format == ".jpeg") { $text = "TEXT IMAGES"; $ch = "../include/kartika.ttf"; $pic = imagecreatefromjpeg($_FILES["file"]["tmp_name"]); header("Content-type: image/jpeg"); $color = imagecolorallocatealpha($pic, 0, 0, 0, 20); $bbox = imagettfbbox(12, 0, $ch, $text); $x = imagesx($pic) - $bbox[2] - 6; $y = imagesy($pic) - $bbox[3] - 6; $width = 0; if(imagesx($pic) > 600) {$width = 1;} imagettftext($pic, 12, 0, $x-1, $y, $color, $ch, $text); imagettftext($pic, 12, 0, $x+1, $y+1, $color, $ch, $text); imagettftext($pic, 12, 0, $x-1, $y-1, $color, $ch, $text); imagettftext($pic, 12, 0, $x, $y, imagecolorallocatealpha($pic, 255, 255, 255, 20), $ch, $text); imagejpeg($pic, ".../upload/news/$_GET[id]/$filename", 100); imagedestroy($pic); header("Content-type: text/html"); mysql_query("INSERT INTO `news_contents` (`section`, `number`, `type`, `fname`, `width`) VALUES('$_GET[id]', '$filenumb', '$filetype', '$filename', '$width')"); } } else {$error = "Размер изображения превышает 2мб.";} } else { if(is_uploaded_file($_FILES["file"]["tmp_name"])) { if($filesize < (5*1024*1048576)) { move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/news/$_GET[id]/$filename"); mysql_query("INSERT INTO `news_contents` (`section`, `number`, `type`, `size`, `fname`, `oname`) VALUES('$_GET[id]', '$filenumb', '$filetype', '$filesize', '$filename', '$fileoname')"); } else {$error = "Размер файла превышает 5гб.";} } } } } } |