Esempio n. 1
0
 static function ftp_image_close()
 {
     if (ImageLib::$ftp_image_connect_id) {
         ftp_close(ImageLib::$ftp_image_connect_id);
         ImageLib::$ftp_image_connect_id = false;
     }
 }
Esempio n. 2
0
 function resize()
 {
     $mainframe =& JFactory::getApplication();
     $jshopConfig =& JSFactory::getConfig();
     require_once $jshopConfig->path . 'lib/image.lib.php';
     JPluginHelper::importPlugin('jshoppingadmin');
     $dispatcher =& JDispatcher::getInstance();
     $filelist = glob($jshopConfig->image_product_path . '/' . 'full_*');
     foreach ($filelist as $key => $value) {
         $url = $value;
         $url_parts = pathinfo($url);
         //filenames
         $name_full = $url_parts['basename'];
         $name_image = substr($url_parts['basename'], 5);
         $name_thumb = "thumb_" . $name_image;
         //file path
         $path_image = $jshopConfig->image_product_path . '/' . $name_image;
         $path_thumb = $jshopConfig->image_product_path . '/' . $name_thumb;
         $path_full = $jshopConfig->image_product_path . '/' . $name_full;
         //resize thumb
         $product_width_image = $jshopConfig->image_product_width;
         $product_height_image = $jshopConfig->image_product_height;
         if (!ImageLib::resizeImageMagic($path_full, $product_width_image, $product_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
             JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL . " " . $name_thumb);
             saveToLog("error.log", "Resize Product Image - Error create thumbail " . $name_thumb);
             $error = 1;
         }
         //resize image
         $product_full_width_image = $jshopConfig->image_product_full_width;
         $product_full_height_image = $jshopConfig->image_product_full_height;
         if (!ImageLib::resizeImageMagic($path_full, $product_full_width_image, $product_full_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_image, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
             JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL . " " . $name_image);
             saveToLog("error.log", "Resize Product Image - Error create image " . $name_image);
             $error = 1;
         }
         $dispatcher->trigger('onAfterSaveProductImage', array($product_id, $name_image));
     }
     if (!JRequest::getInt("noredirect")) {
         $mainframe->redirect("index.php?option=com_jshopping&controller=resize&task=view", _JSHOP_COMPLETED);
     }
 }
 function uploadImage($post)
 {
     $jshopConfig = JSFactory::getConfig();
     $dispatcher = JDispatcher::getInstance();
     $upload = new UploadFile($_FILES['category_image']);
     $upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
     $upload->setDir($jshopConfig->image_category_path);
     $upload->setFileNameMd5(0);
     $upload->setFilterName(1);
     if ($upload->upload()) {
         $name = $upload->getName();
         if ($post['old_image'] && $name != $post['old_image']) {
             @unlink($jshopConfig->image_category_path . "/" . $post['old_image']);
         }
         @chmod($jshopConfig->image_category_path . "/" . $name, 0777);
         if ($post['size_im_category'] < 3) {
             if ($post['size_im_category'] == 1) {
                 $category_width_image = $jshopConfig->image_category_width;
                 $category_height_image = $jshopConfig->image_category_height;
             } else {
                 $category_width_image = JRequest::getInt('category_width_image');
                 $category_height_image = JRequest::getInt('category_height_image');
             }
             $path_full = $jshopConfig->image_category_path . "/" . $name;
             $path_thumb = $jshopConfig->image_category_path . "/" . $name;
             if ($category_width_image || $category_height_image) {
                 if (!ImageLib::resizeImageMagic($path_full, $category_width_image, $category_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
                     JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                     saveToLog("error.log", "SaveCategory - Error create thumbail");
                 }
             }
             @chmod($jshopConfig->image_category_path . "/" . $name, 0777);
         }
         $category_image = $name;
         $dispatcher->trigger('onAfterSaveCategoryImage', array(&$post, &$category_image, &$path_full, &$path_thumb));
     } else {
         $category_image = '';
         if ($upload->getError() != 4) {
             JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
             saveToLog("error.log", "SaveCategory - Error upload image. code: " . $upload->getError());
         }
     }
     return $category_image;
 }
Esempio n. 4
0
 function uploadImages($product, $product_id, $post)
 {
     $jshopConfig = JSFactory::getConfig();
     $dispatcher = JDispatcher::getInstance();
     for ($i = 0; $i < $jshopConfig->product_image_upload_count; $i++) {
         $upload = new UploadFile($_FILES['product_image_' . $i]);
         $upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
         $upload->setDir($jshopConfig->image_product_path);
         $upload->setFileNameMd5(0);
         $upload->setFilterName(1);
         if ($upload->upload()) {
             $name_image = $upload->getName();
             $name_thumb = 'thumb_' . $name_image;
             $name_full = 'full_' . $name_image;
             @chmod($jshopConfig->image_product_path . "/" . $name_image, 0777);
             $path_image = $jshopConfig->image_product_path . "/" . $name_image;
             $path_thumb = $jshopConfig->image_product_path . "/" . $name_thumb;
             $path_full = $jshopConfig->image_product_path . "/" . $name_full;
             rename($path_image, $path_full);
             if ($jshopConfig->image_product_original_width || $jshopConfig->image_product_original_height) {
                 if (!ImageLib::resizeImageMagic($path_full, $jshopConfig->image_product_original_width, $jshopConfig->image_product_original_height, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_full, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
                     JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                     saveToLog("error.log", "SaveProduct - Error create thumbail");
                     $error = 1;
                 }
             }
             $error = 0;
             if ($post['size_im_product'] == 3) {
                 copy($path_full, $path_thumb);
                 @chmod($path_thumb, 0777);
             } else {
                 if ($post['size_im_product'] == 1) {
                     $product_width_image = $jshopConfig->image_product_width;
                     $product_height_image = $jshopConfig->image_product_height;
                 } else {
                     $product_width_image = JRequest::getInt('product_width_image');
                     $product_height_image = JRequest::getInt('product_height_image');
                 }
                 if (!ImageLib::resizeImageMagic($path_full, $product_width_image, $product_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
                     JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                     saveToLog("error.log", "SaveProduct - Error create thumbail");
                     $error = 1;
                 }
                 @chmod($path_thumb, 0777);
                 unset($img);
             }
             if ($post['size_full_product'] == 3) {
                 copy($path_full, $path_image);
                 @chmod($path_image, 0777);
             } else {
                 if ($post['size_full_product'] == 1) {
                     $product_full_width_image = $jshopConfig->image_product_full_width;
                     $product_full_height_image = $jshopConfig->image_product_full_height;
                 } else {
                     $product_full_width_image = JRequest::getInt('product_full_width_image');
                     $product_full_height_image = JRequest::getInt('product_full_height_image');
                 }
                 if (!ImageLib::resizeImageMagic($path_full, $product_full_width_image, $product_full_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_image, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
                     JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                     $error = 1;
                 }
                 @chmod($path_image, 0777);
                 unset($img);
             }
             if (!$error) {
                 $this->addToProductImage($product_id, $name_image, $post["product_image_descr_" . $i]);
                 $dispatcher->trigger('onAfterSaveProductImage', array($product_id, $name_image));
             }
         } else {
             if ($upload->getError() != 4) {
                 JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
                 saveToLog("error.log", "SaveProduct - Error upload image. code: " . $upload->getError());
             }
         }
         unset($upload);
     }
     for ($i = 0; $i < $jshopConfig->product_image_upload_count; $i++) {
         if ($post['product_folder_image_' . $i] != '') {
             if (file_exists($jshopConfig->image_product_path . '/' . $post['product_folder_image_' . $i])) {
                 $name_image = $post['product_folder_image_' . $i];
                 $name_thumb = 'thumb_' . $name_image;
                 $name_full = 'full_' . $name_image;
                 $this->addToProductImage($product_id, $name_image, $post["product_image_descr_" . $i]);
                 $dispatcher->trigger('onAfterSaveProductFolerImage', array($product_id, $name_full, $name_image, $name_thumb));
             }
         }
     }
     if (!$product->image) {
         $list_images = $product->getImages();
         if (count($list_images)) {
             $product = JTable::getInstance('product', 'jshop');
             $product->load($product_id);
             $product->image = $list_images[0]->image_name;
             $product->store();
         }
     }
     if (isset($post['old_image_descr'])) {
         $this->renameProductImageOld($post['old_image_descr'], $post['old_image_ordering']);
     }
 }
Esempio n. 5
0
 function save()
 {
     $jshopConfig = JSFactory::getConfig();
     require_once $jshopConfig->path . 'lib/image.lib.php';
     require_once $jshopConfig->path . 'lib/uploadfile.class.php';
     $dispatcher = JDispatcher::getInstance();
     $apply = JRequest::getVar("apply");
     $_alias = JSFactory::getModel("alias");
     $db = JFactory::getDBO();
     $man = JSFactory::getTable('manufacturer', 'jshop');
     $man_id = JRequest::getInt("manufacturer_id");
     $post = JRequest::get("post");
     $_lang = JSFactory::getModel("languages");
     $languages = $_lang->getAllLanguages(1);
     foreach ($languages as $lang) {
         $post['name_' . $lang->language] = trim($post['name_' . $lang->language]);
         if ($jshopConfig->create_alias_product_category_auto && $post['alias_' . $lang->language] == "") {
             $post['alias_' . $lang->language] = $post['name_' . $lang->language];
         }
         $post['alias_' . $lang->language] = JApplication::stringURLSafe($post['alias_' . $lang->language]);
         if ($post['alias_' . $lang->language] != "" && !$_alias->checkExistAlias1Group($post['alias_' . $lang->language], $lang->language, 0, $man_id)) {
             $post['alias_' . $lang->language] = "";
             JError::raiseWarning("", _JSHOP_ERROR_ALIAS_ALREADY_EXIST);
         }
         $post['description_' . $lang->language] = JRequest::getVar('description' . $lang->id, '', 'post', "string", 2);
         $post['short_description_' . $lang->language] = JRequest::getVar('short_description_' . $lang->language, '', 'post', "string", 2);
     }
     if (!$post['manufacturer_publish']) {
         $post['manufacturer_publish'] = 0;
     }
     $dispatcher->trigger('onBeforeSaveManufacturer', array(&$post));
     if (!$man->bind($post)) {
         JError::raiseWarning("", _JSHOP_ERROR_BIND);
         $this->setRedirect("index.php?option=com_jshopping&controller=manufacturers");
         return 0;
     }
     if (!$man_id) {
         $man->ordering = null;
         $man->ordering = $man->getNextOrder();
     }
     $upload = new UploadFile($_FILES['manufacturer_logo']);
     $upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
     $upload->setDir($jshopConfig->image_manufs_path);
     $upload->setFileNameMd5(0);
     $upload->setFilterName(1);
     if ($upload->upload()) {
         if ($post['old_image']) {
             @unlink($jshopConfig->image_manufs_path . "/" . $post['old_image']);
         }
         $name = $upload->getName();
         @chmod($jshopConfig->image_manufs_path . "/" . $name, 0777);
         if ($post['size_im_category'] < 3) {
             if ($post['size_im_category'] == 1) {
                 $category_width_image = $jshopConfig->image_category_width;
                 $category_height_image = $jshopConfig->image_category_height;
             } else {
                 $category_width_image = JRequest::getInt('category_width_image');
                 $category_height_image = JRequest::getInt('category_height_image');
             }
             $path_full = $jshopConfig->image_manufs_path . "/" . $name;
             $path_thumb = $jshopConfig->image_manufs_path . "/" . $name;
             if (!ImageLib::resizeImageMagic($path_full, $category_width_image, $category_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color, $jshopConfig->image_interlace)) {
                 JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                 saveToLog("error.log", "SaveManufacturer - Error create thumbail");
             }
             @chmod($jshopConfig->image_manufs_path . "/" . $name, 0777);
             unset($img);
         }
         $man->manufacturer_logo = $name;
     } else {
         if ($upload->getError() != 4) {
             JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
             saveToLog("error.log", "SaveManufacturer - Error upload image. code: " . $upload->getError());
         }
     }
     if (!$man->store()) {
         JError::raiseWarning("", _JSHOP_ERROR_SAVE_DATABASE);
         $this->setRedirect("index.php?option=com_jshopping&controller=manufacturers");
         return 0;
     }
     $dispatcher->trigger('onAfterSaveManufacturer', array(&$man));
     if ($this->getTask() == 'apply') {
         $this->setRedirect("index.php?option=com_jshopping&controller=manufacturers&task=edit&man_id=" . $man->manufacturer_id);
     } else {
         $this->setRedirect("index.php?option=com_jshopping&controller=manufacturers");
     }
 }
Esempio n. 6
0
             break;
         case "image/pjpeg":
         case "image/jpeg":
         case "image/jpg":
             $createdImage = imagejpeg($newImage, $tempName, 99);
             break;
         case "image/png":
         case "image/x-png":
             $createdImage = imagepng($newImage, $tempName);
             break;
     }
     if ($createdImage) {
         if (ImageLib::ftp_check_dir('up_new', true)) {
             if (ImageLib::ftp_image_put_file($cropName, $tempName)) {
                 unlink($tempName);
                 ImageLib::ftp_image_delete_file($imageName);
                 $return = 'true';
             } else {
                 $return = 'false,Copy file failed, permission denied';
             }
         } else {
             $return = 'false,Destination folder not found';
         }
     } else {
         $return = 'false,Refine image failed';
     }
 } else {
     switch ($imageType) {
         case "image/gif":
             $createdImage = imagegif($newImage, $cropName);
             break;
 /**
  * Create a thumbnail from a file
  *
  * @param  string $file
  * @param  string $thumb
  * @param  int    $size
  */
 protected function createThumb($file, $thumb, $size)
 {
     // open file a image resource
     $img = ImageLib::make($file);
     // crop the best fitting 1:1 ratio and resize to the size given
     $img->grab($size);
     // save the same file as jpeg with default quality
     $img->save($thumb);
 }
function FileUpload($resourceType, $currentFolder, $sCommand)
{
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        global $Config;
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sFileName = SanitizeFileName($sFileName);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        if (isset($Config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($Config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                $sErrorNumber = '202';
            }
        }
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '201';
                } else {
                    //Add by Le Huu Binh 25-05-2010
                    $image = new ImageLib();
                    $image->load($oFile['tmp_name']);
                    $orinWidth = $image->getWidth();
                    if ($orinWidth > 500) {
                        $image->resizeToWidth(500);
                    }
                    $image->save($sFilePath);
                    //End Add by Le Huu Binh
                    //Line below was disabled by Le Huu Binh
                    //move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
                    if (is_file($sFilePath)) {
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        $oldumask = umask(0);
                        chmod($sFilePath, $permissions);
                        umask($oldumask);
                    }
                    break;
                }
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    exit;
}
 function save()
 {
     $mainframe = JFactory::getApplication();
     $jshopConfig = JSFactory::getConfig();
     require_once $jshopConfig->path . 'lib/image.lib.php';
     require_once $jshopConfig->path . 'lib/uploadfile.class.php';
     JPluginHelper::importPlugin('jshoppingadmin');
     $dispatcher = JDispatcher::getInstance();
     $_alias = $this->getModel("alias");
     $db = JFactory::getDBO();
     $category = JTable::getInstance("category", "jshop");
     if (!$_POST["category_id"]) {
         $_POST['category_add_date'] = getJsDate();
     }
     if (!isset($_POST['category_publish'])) {
         $_POST['category_publish'] = 0;
     }
     $post = JRequest::get('post');
     $_lang = $this->getModel("languages");
     $languages = $_lang->getAllLanguages(1);
     if ($post['category_parent_id'] == $post['category_id']) {
         $post['category_parent_id'] = 0;
     }
     $dispatcher->trigger('onBeforeSaveCategory', array(&$post));
     foreach ($languages as $lang) {
         $post['name_' . $lang->language] = trim($post['name_' . $lang->language]);
         if ($jshopConfig->create_alias_product_category_auto && $post['alias_' . $lang->language] == "") {
             $post['alias_' . $lang->language] = $post['name_' . $lang->language];
         }
         $post['alias_' . $lang->language] = JApplication::stringURLSafe($post['alias_' . $lang->language]);
         if ($post['alias_' . $lang->language] != "" && !$_alias->checkExistAlias1Group($post['alias_' . $lang->language], $lang->language, $post['category_id'], 0)) {
             $post['alias_' . $lang->language] = "";
             JError::raiseWarning("", _JSHOP_ERROR_ALIAS_ALREADY_EXIST);
         }
         $post['description_' . $lang->language] = JRequest::getVar('description' . $lang->id, '', 'post', "string", 2);
         $post['short_description_' . $lang->language] = JRequest::getVar('short_description_' . $lang->language, '', 'post', "string", 2);
     }
     if (!$category->bind($post)) {
         JError::raiseWarning("", _JSHOP_ERROR_BIND);
         $this->setRedirect("index.php?option=com_jshopping&controller=categories");
         return 0;
     }
     $edit = $category->category_id;
     $upload = new UploadFile($_FILES['category_image']);
     $upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
     $upload->setDir($jshopConfig->image_category_path);
     $upload->setFileNameMd5(0);
     $upload->setFilterName(1);
     if ($upload->upload()) {
         $name = $upload->getName();
         if ($post['old_image'] && $name != $post['old_image']) {
             @unlink($jshopConfig->image_category_path . "/" . $post['old_image']);
         }
         @chmod($jshopConfig->image_category_path . "/" . $name, 0777);
         if ($post['size_im_category'] < 3) {
             if ($post['size_im_category'] == 1) {
                 $category_width_image = $jshopConfig->image_category_width;
                 $category_height_image = $jshopConfig->image_category_height;
             } else {
                 $category_width_image = JRequest::getInt('category_width_image');
                 $category_height_image = JRequest::getInt('category_height_image');
             }
             $path_full = $jshopConfig->image_category_path . "/" . $name;
             $path_thumb = $jshopConfig->image_category_path . "/" . $name;
             if (!ImageLib::resizeImageMagic($path_full, $category_width_image, $category_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
                 JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                 saveToLog("error.log", "SaveCategory - Error create thumbail");
             }
             @chmod($jshopConfig->image_category_path . "/" . $name, 0777);
             unset($img);
         }
         $category->category_image = $name;
     } else {
         if ($upload->getError() != 4) {
             JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
             saveToLog("error.log", "SaveCategory - Error upload image. code: " . $upload->getError());
         }
     }
     $this->_reorderCategory($category);
     if (!$category->store()) {
         JError::raiseWarning("", _JSHOP_ERROR_SAVE_DATABASE);
         $this->setRedirect("index.php?option=com_jshopping&controller=categories");
         return 0;
     }
     $dispatcher->trigger('onAfterSaveCategory', array(&$category));
     $success = $edit ? _JSHOP_CATEGORY_SUCC_UPDATE : _JSHOP_CATEGORY_SUCC_ADDED;
     if ($this->getTask() == 'apply') {
         $this->setRedirect('index.php?option=com_jshopping&controller=categories&task=edit&category_id=' . $category->category_id, $success);
     } else {
         $this->setRedirect('index.php?option=com_jshopping&controller=categories', $success);
     }
 }
Esempio n. 10
0
 static function thumbImageNoBG($imageSource, $width = 0, $height = 0)
 {
     if ($width <= 0 && $height <= 0) {
         return '';
     }
     if ($imageSource != '') {
         if (!file_exists(EnBacImage::$path . UP_FOLDER . "/" . $imageSource)) {
             $imageSource = DEFAULT_IMAGE;
         }
     } else {
         $imageSource = DEFAULT_IMAGE;
     }
     $file_ext = self::getExtension($imageSource);
     if ($height && $width) {
         $thumbDir = "thumb_in/{$width}_{$height}/";
     } else {
         $thumbDir = '';
     }
     if ($thumbDir && $imageSource == DEFAULT_IMAGE) {
         //Nếu ở chế độ view ảnh thumb mà k thấy ảnh gốc!
         header("HTTP/1.0 404 Not Found");
         echo "<h1>404 - Not Found!</h1>";
         exit;
     }
     $get_direct_img = false;
     if (CACHE_ON) {
         $tempCacheDir = '';
         $tempCacheFile = '';
         if ($thumbDir) {
             $cacheDir = $thumbDir . dirname($imageSource) . '/';
             $tempCacheDir = IMG_TEMP_DIR . $cacheDir;
             $tempCacheFile = $tempCacheDir . basename($imageSource);
             $cache_file = $thumbDir . $imageSource;
             $checkCacheFile = CHECK_PATH . $cache_file;
         } else {
             if ($imageSource != DEFAULT_IMAGE) {
                 $cacheDir = dirname($imageSource);
                 if (strpos($imageSource, 'category/') === 0) {
                     $cacheDir = 'category';
                 }
                 $tempCacheDir = $cacheDir;
                 if ($cacheDir != '' && (is_dir($cacheDir) || $cacheDir == 'category') && $cacheDir != '.') {
                     $cacheDir = IMG_CACHE_PATH . $cacheDir . '/';
                     $tempCacheDir = IMG_TEMP_DIR . $cacheDir . '/';
                 } else {
                     $cacheDir = IMG_CACHE_PATH . 'enbac/';
                     $tempCacheDir = IMG_TEMP_DIR . 'enbac/';
                 }
             } else {
                 $get_direct_img = true;
                 $cacheDir = IMG_CACHE_PATH . 'blank/';
                 $tempCacheDir = IMG_TEMP_DIR . 'blank/';
             }
             $QUERY_STRING = $_SERVER['QUERY_STRING'];
             if (isset($_GET['delimg'])) {
                 $QUERY_STRING = str_replace(array('delimg=' . $_GET['delimg'] . '&', '&delimg=' . $_GET['delimg'], 'delimg=' . $_GET['delimg']), '', $QUERY_STRING);
             }
             $cache_file = md5(str_replace("&amp;", "&", $QUERY_STRING)) . $file_ext;
             $tempCacheFile = $tempCacheDir . $cache_file;
             $cache_file = $cacheDir . $cache_file;
             $checkCacheFile = CHECK_PATH . $cache_file;
         }
         $del_cache = (int) (isset($_GET['delimg']) && (int) $_GET['delimg'] == 1);
         //Lấy cache ra:
         if (@file_exists($checkCacheFile) && !$del_cache) {
             @header("Location: " . IMG_CACHE_URL . $cache_file);
             exit;
         }
     }
     $thumbImage = new EnBacImage();
     $thumbImage->loadfile(UP_FOLDER . "/" . $imageSource, $get_direct_img);
     if ($thumbImage->width > $width || $thumbImage->height > $height) {
         if ($thumbImage->width / $thumbImage->height <= $width / $height) {
             $thumbImage->resizetoheight($height);
         } else {
             $thumbImage->resizetowidth($width);
         }
     }
     if (CACHE_ON && $cache_file) {
         if (FTP_CACHE && $tempCacheFile && ImageLib::CheckDir($tempCacheDir) && ImageLib::ftp_check_dir($cacheDir)) {
             //Che do ghi cache qua ftp
             $thumbImage->savefile($tempCacheFile);
             if (@file_exists($tempCacheFile)) {
                 //upload file via ftp
                 ImageLib::ftp_image_delete_file($cache_file);
                 ImageLib::ftp_image_put_file($cache_file, $tempCacheFile);
                 @unlink($tempCacheFile);
                 ImageLib::ftp_image_close();
             }
         } elseif (ImageLib::CheckDir($cacheDir)) {
             $thumbImage->savefile($cache_file);
         }
         if (!FIRST_SHOW_IMAGE && @file_exists($checkCacheFile)) {
             @header("Location: " . IMG_CACHE_URL . $cache_file);
             imagedestroy($thumbImage->ImageStream);
             exit;
         }
     }
     //show img
     if (SET_HEADER) {
         //standard method #
         header('HTTP/1.0 200 OK');
         //HTTP/1.1 200 OK
         //CGI method #
         header('Status: 200 OK');
         header("Expires: ");
         header("Last-Modified: ");
         header('Cache-Control: public,max-age=2592000');
         //Adjust maxage appropriately
         header('Pragma: public');
         //header("Cache-Control: public, must-revalidate");header("Pragma: hack");
     }
     if (stripos($_SERVER['HTTP_USER_AGENT'], "msie") === false) {
         header('Content-type: ' . $thumbImage->mimetype);
     }
     if (SET_HEADER) {
         header('Content-Disposition: inline; filename=' . basename($imageSource, $file_ext));
     }
     $thumbImage->showImage($quality);
     imagedestroy($thumbImage->ImageStream);
     exit;
 }