Beispiel #1
0
 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;
 }