} elseif (!gcms::testDir(DATA_PATH . "gallery/{$index['id']}/")) { $ret['ret_gallery_pic'] = 'DO_NOT_UPLOAD'; $input = 'gallery_pic'; $error = 'DO_NOT_UPLOAD'; } else { // อัปโหลดรูปภาพจริง $res = gcms::resizeImage($file['tmp_name'], DATA_PATH . "gallery/{$index['id']}/", "0.{$info['ext']}", $info, $config['gallery_image_w']); if (!$res) { $ret['ret_gallery_pic'] = 'DO_NOT_UPLOAD'; $input = 'gallery_pic'; $error = 'DO_NOT_UPLOAD'; } else { $save2['image'] = $res['name']; } // อัปโหลด thumbnail if (!gcms::cropImage($file['tmp_name'], DATA_PATH . "gallery/{$index['id']}/thumb_{$save2['image']}", $info, $config['gallery_thumb_w'], $config['gallery_thumb_h'])) { $ret['ret_gallery_pic'] = 'DO_NOT_UPLOAD'; $input = 'gallery_pic'; $error = 'DO_NOT_UPLOAD'; } // ลบไฟล์เดิม if (!empty($index['image']) && $save2['image'] != $index['image']) { @unlink(DATA_PATH . "gallery/{$index['id']}/{$index['image']}"); @unlink(DATA_PATH . "gallery/{$index['id']}/thumb_{$index['image']}"); } } } } if (!$error) { // save $save['last_update'] = $mmktime;
$ret['ret_write_picture'] = 'REQUIRE_PICTURE'; $ret['error'] = 'REQUIRE_PICTURE'; $ret['input'] = 'write_picture'; } else { // อัปโหลดรูปภาw if ($icon['tmp_name'] != '') { // ตรวจสอบไฟล์อัปโหลด $info = gcms::isValidImage(array('jpg', 'gif', 'png'), $icon); if (!$info) { $ret['ret_write_picture'] = 'INVALID_FILE_TYPE'; $input = 'write_picture'; $error = 'INVALID_FILE_TYPE'; } else { $save['picture'] = $index[0]['id'] . '.jpg'; // อัปโหลด if (!gcms::cropImage($icon['tmp_name'], DATA_PATH . "personnel/{$save['picture']}", $info, $config['personnel_image_w'], $config['personnel_image_h'])) { $ret['ret_write_picture'] = 'DO_NOT_UPLOAD'; $input = 'write_picture'; $error = 'DO_NOT_UPLOAD'; } else { $ret['imgIcon'] = rawurlencode(DATA_URL . "personnel/{$save['picture']}?{$mmktime}"); } // ลบไฟล์เดิม if ($save['picture'] != $index[0]['picture']) { @unlink(DATA_PATH . 'personnel/' . $index[0]['picture']); } } } if (!$error) { if ($id == 0) { // ใหม่
if (!$info) { $ret['error'] = 'INVALID_FILE_TYPE'; } else { while (is_file($dir . "{$save['count']}.{$info['ext']}")) { $save['count']++; } $save['image'] = "{$save['count']}.{$info['ext']}"; // อัปโหลดรูปภาพจริง $res = gcms::resizeImage($file['tmp_name'], $dir, $save['image'], $info, $config['gallery_image_w']); if (!$res) { $ret['error'] = 'DO_NOT_UPLOAD'; } else { $save['image'] = $res['name']; } // อัปโหลด thumbnail if (!gcms::cropImage($file['tmp_name'], $dir . "thumb_{$save['image']}", $info, $config['gallery_thumb_w'], $config['gallery_thumb_h'])) { $ret['error'] = 'DO_NOT_UPLOAD'; } else { // บันทึกลง db $db->add(DB_GALLERY, $save); } } } // อัปเดทจำนวนรูปภาพในอัลบัม $sql1 = "SELECT COUNT(*) FROM `" . DB_GALLERY . "` WHERE `album_id`=C.`id` AND `module_id`='{$index['module_id']}'"; $sql = "UPDATE `" . DB_GALLERY_ALBUM . "` AS C SET C.`count`=({$sql1}) WHERE C.`id`='{$index['id']}' AND C.`module_id`='{$index['module_id']}'"; $db->query($sql); } else { $ret['error'] = 'ACTION_ERROR'; } }
// อัปโหลด foreach ($_FILES as $key => $file) { if (!$error && $file['tmp_name'] != '') { // ตรวจสอบไฟล์อัปโหลด $info = gcms::isValidImage($img_typies, $file); if (!$info) { // ชนิดไฟล์อัปโหลด $ret["ret_{$key}"] = 'INVALID_FILE_TYPE'; $input = !$input ? $key : $input; $error = !$error ? 'INVALID_FILE_TYPE' : $error; } else { $ret["ret_{$key}"] = ''; // อัปโหลด $k = str_replace('write_', '', $key); $save[$k] = "{$k}-{$index['module_id']}-{$index['id']}.{$info['ext']}"; if (!gcms::cropImage($file['tmp_name'], "{$dir}/{$save[$k]}", $info, $index['icon_width'], $index['icon_height'])) { $ret["ret_{$key}"] = 'DO_NOT_UPLOAD'; $input = !$error ? $key : $input; $error = !$error ? 'DO_NOT_UPLOAD' : $error; } else { $ret["ret_{$key}"] = ''; $save[$k . 'W'] = $index['icon_width']; $save[$k . 'H'] = $index['icon_height']; // ลบรูปภาพเดิม if (isset($index[$k]) && $index[$k] != $save[$k]) { @unlink(DATA_PATH . "document/{$index[$k]}"); } } } } }
} else { if ($user['icon'] != '') { @unlink(USERICON_FULLPATH . $user['icon']); } // สร้างรูป thumbnail if ($info['width'] == $config['user_icon_w'] && $info['height'] == $config['user_icon_h']) { $save['icon'] = "{$user['id']}.{$info['ext']}"; if (!@move_uploaded_file($register_usericon['tmp_name'], USERICON_FULLPATH . $save['icon'])) { $ret['ret_register_usericon'] = 'DO_NOT_UPLOAD'; $input = !$input ? 'register_usericon' : $input; $error = !$error ? 'DO_NOT_UPLOAD' : $error; } } else { // ปรับภาพตามขนาดที่กำหนด $save['icon'] = "{$user['id']}.jpg"; if (!gcms::cropImage($register_usericon['tmp_name'], USERICON_FULLPATH . $save['icon'], $info, $config['user_icon_w'], $config['user_icon_h'])) { $ret['ret_register_usericon'] = 'DO_NOT_UPLOAD'; $input = !$input ? 'register_usericon' : $input; $error = !$error ? 'DO_NOT_UPLOAD' : $error; } } if (!$error) { // คืนค่า url ของรูปใหม่ $ret['imgIcon'] = rawurlencode(WEB_URL . '/modules/member/usericon.php?w=70&id=' . $user['id'] . '&' . $mmktime); $ret['ret_register_usericon'] = ''; } } } if (!$error) { if (!$isAdmin) { // ไม่ใช่แอดมิน ห้ามแก้ไข email,status,point
} else { // ชื่อไฟล์ใหม่ $icon = DATA_FOLDER . "document/default-{$index['id']}"; if ($info['width'] <= $icon_width && $info['height'] <= $icon_height) { // รูปภาพต้นฉบับ เท่ากับ หรือ เล็กกว่าที่กำหนดให้อัปโหลดเลย if (!@move_uploaded_file($default_icon['tmp_name'], ROOT_PATH . "{$icon}.{$info['ext']}")) { $ret['error'] = 'DO_NOT_UPLOAD'; $ret['input'] = 'config_default_icon'; $ret['ret_config_default_icon'] = 'DO_NOT_UPLOAD'; } else { $cfg[] = "icon_w={$info['width']}"; $cfg[] = "icon_h={$info['height']}"; $cfg[] = "default_icon={$icon}.{$info['ext']}"; $ret['img_default_icon'] = rawurlencode(WEB_URL . "/{$icon}.{$info['ext']}?{$mmktime}"); } } elseif (!gcms::cropImage($default_icon['tmp_name'], ROOT_PATH . "{$icon}.jpg", $info, $icon_width, $icon_height)) { $ret['error'] = 'DO_NOT_UPLOAD'; $ret['input'] = 'config_default_icon'; $ret['ret_config_default_icon'] = 'DO_NOT_UPLOAD'; } else { $cfg[] = "icon_w={$icon_width}"; $cfg[] = "icon_h={$icon_height}"; $cfg[] = "default_icon={$icon}.jpg"; $ret['img_default_icon'] = rawurlencode(WEB_URL . "/{$icon}.jpg?{$mmktime}"); $ret['ret_config_default_icon'] = ''; } } } else { // อ่านไอคอนเดิมมาใช้แทน $cfg[] = "icon_w={$index['icon_w']}"; $cfg[] = "icon_h={$index['icon_h']}";
$ret['ret_download_thumbnail'] = 'INVALID_FILE_TYPE'; $error = true; } else { $thumb = "thumb-{$last_id}"; if ($info['width'] <= $config['download_thumb_width'] && $info['height'] <= $config['download_thumb_width']) { // รูปภาพต้นฉบับ เท่ากับ หรือ เล็กกว่าที่กำหนดให้อัปโหลดเลย if (!@copy($thumbnail['tmp_name'], DATA_PATH . "download/{$thumb}.{$info['ext']}")) { $ret['error'] = 'DO_NOT_UPLOAD'; $ret['ret_download_thumbnail'] = 'DO_NOT_UPLOAD'; $error = true; } else { $save['thumb'] = "{$thumb}.{$info['ext']}"; $save['thumb_w'] = $info['width']; $save['thumb_h'] = $info['height']; } } elseif (!gcms::cropImage($thumbnail['tmp_name'], DATA_PATH . "download/{$thumb}.jpg", $info, $config['download_thumb_width'], $config['download_thumb_width'])) { $ret['error'] = 'DO_NOT_UPLOAD'; $error = true; } else { $save['thumb'] = "{$thumb}.jpg"; $save['thumb_w'] = $config['download_thumb_width']; $save['thumb_h'] = $config['download_thumb_width']; } } } if (!$error) { $save['count'] = $id > 0 ? $file['count'] : 0; $save['last_update'] = $mmktime; // thumb if ($save['thumb'] != '') { $icon = DATA_URL . 'download/' . $save['thumb'];
if (!$info) { $ret["ret_{$key}"] = 'INVALID_FILE_TYPE'; $input = $key; $error = 'INVALID_FILE_TYPE'; } else { $icon[$k] = "cat-{$k}-{$index['id']}.{$info['ext']}"; if ($info['width'] <= $index['icon_width'] && $info['height'] <= $index['icon_height']) { // รูปภาพต้นฉบับ เท่ากับ หรือ เล็กกว่าที่กำหนดให้อัปโหลดเลย if (!@move_uploaded_file($value['tmp_name'], DATA_PATH . "board/{$icon[$k]}")) { $ret["ret_{$key}"] = 'DO_NOT_UPLOAD'; $input = $key; $error = 'DO_NOT_UPLOAD'; } else { $ret["icon_{$k}"] = rawurlencode(DATA_URL . "board/{$icon[$k]}?{$mmktime}"); } } elseif (!gcms::cropImage($value['tmp_name'], DATA_PATH . "board/{$icon[$k]}", $info, $index['icon_width'], $index['icon_height'])) { $ret["ret_{$key}"] = 'DO_NOT_UPLOAD'; $input = $key; $error = 'DO_NOT_UPLOAD'; } else { $ret["icon_{$k}"] = rawurlencode(DATA_URL . "board/{$icon[$k]}?{$mmktime}"); } } } } if (sizeof($icon) > 0) { $save['icon'] = gcms::array2Ser($icon); } } if (!$error) { $save['category_id'] = $category_id;
$ret['input'] = 'board_picture'; $ret['ret_board_picture'] = 'INVALID_FILE_TYPE'; } elseif ($picture['size'] > $index['img_upload_size'] * 1024) { $ret['error'] = 'FILE_TOO_BIG'; $ret['input'] = 'board_picture'; $ret['ret_board_picture'] = 'FILE_TOO_BIG'; } else { // ชื่อไฟล์ $save['picture'] = "{$mmktime}.{$info['ext']}"; while (is_file(DATA_PATH . "board/{$save['picture']}")) { $mmktime++; $save['picture'] = "{$mmktime}.{$info['ext']}"; } // อัปโหลดรูป $tw = max(32, (int) $index['thumb_width']); if (!gcms::cropImage($picture['tmp_name'], DATA_PATH . "board/thumb-{$save['picture']}", $info, $tw, $tw)) { $ret['error'] = 'DO_NOT_UPLOAD'; $ret['input'] = 'board_picture'; $ret['ret_board_picture'] = 'DO_NOT_UPLOAD'; } elseif (!@move_uploaded_file($picture['tmp_name'], DATA_PATH . "board/{$save['picture']}")) { $ret['error'] = 'DO_NOT_UPLOAD'; $ret['input'] = 'board_picture'; $ret['ret_board_picture'] = 'DO_NOT_UPLOAD'; } else { $save['pictureW'] = $info['width']; $save['pictureH'] = $info['height']; // ลบไฟล์เก่า if ($index['picture'] != '') { @unlink(DATA_PATH . "board/thumb-{$index['picture']}"); @unlink(DATA_PATH . "board/{$index['picture']}"); }