function action() { $photo = array(); $dir = $this->getDir("i/" . strtolower($_GET['classDiv'])); $sort_id = 0; if ($_POST['parentID'] != 0 && ($row = DB::query_row("SELECT sort FROM `photo_tb` WHERE `parentID` = '" . DB::escape($_POST['parentID']) . "' && `table` = '" . DB::escape($_GET['classDiv']) . "' ORDER BY `sort` DESC"))) { $sort_id = $row['sort']; } foreach ($_FILES['img_arr']['tmp_name'] as $k => $v) { $sort_id++; DB::query("INSERT INTO `photo_tb` (`parentID`, `table`, `name`, `sort`) \n\t\t\tVALUES (\n\t\t\t\t'" . DB::escape($_POST['parentID']) . "',\n\t\t\t\t'" . DB::escape($_GET['classDiv']) . "',\n\t\t\t\t'" . DB::escape($_FILES['img_arr']['name'][$k]) . "',\n\t\t\t\t'" . $sort_id . "'\n\t\t\t)"); $insert_id = DB::last_inserted_id(); $_SESSION['photo'][$insert_id] = $insert_id; foreach (Config::$photo[$_GET['classDiv']] as $size) { $this->getDir($dir . "/" . self::getPathFile($insert_id)); $e = explode('x', $size); if (count($e) == 1) { Resize::resizeImage($e['0'], $v, $this->getDir($dir . "/" . self::getPathFile($insert_id) . "/" . $size) . "/" . $_FILES['img_arr']['name'][$k]); } else { Resize::cropImage($e['0'], $e['1'], $v, $this->getDir($dir . "/" . self::getPathFile($insert_id) . "/" . $size) . "/" . $_FILES['img_arr']['name'][$k]); } } copy($v, $dir . "/" . self::getPathFile($insert_id) . "/" . $_FILES['img_arr']['name'][$k]); Resize::resizeImage(80, $v, $this->getDir($dir . "/" . self::getPathFile($insert_id) . "/thumb") . "/" . $_FILES['img_arr']['name'][$k]); $photo[] = array('src' => $dir . "/" . self::getPathFile($insert_id) . "/thumb/" . $_FILES['img_arr']['name'][$k], 'id' => $insert_id, 'sort' => $sort_id); } echo json_encode($photo); die; }
function add() { DB::query("INSERT INTO `" . $this->table_name . "` (`date_add`, `categoryID`, `name`, `description`)\n\t\tVALUES( \n\t\tNOW(),\n\t\t'" . DB::escape($_POST['categoryID']) . "',\n\t\t'" . DB::escape($_POST['name']) . "',\n\t\t'" . DB::escape($_POST['description']) . "'\n\t\t)\n\t\t"); $parent_id = DB::last_inserted_id(); Photo::updateID($parent_id); $main = 0; if (!isset($_POST['main'])) { if ($photo = DB::query_row("SELECT * FROM `photo_tb` WHERE `parentID` = '" . $parent_id . "' && `table` = '" . $this->class_name . "'")) { $main = $photo['id']; } } else { $main = $_POST['main']; } DB::query("UPDATE `" . $this->table_name . "` SET `main` = '" . DB::escape($main) . "' WHERE `id` = '" . $parent_id . "'"); Meta::updatetMeta($parent_id, $this->class_name); }