Exemple #1
0
 function uploadHinhAnhDacBiet($fieldName, $folderName, $id)
 {
     if (!$id) {
         return false;
     }
     require_once JPATH_ROOT . DS . '/libraries/com_u_re/Http_File.php';
     jimport('joomla.filesystem.folder');
     global $u_reGlobalConfig;
     $propertyImagePath = $u_reGlobalConfig['IMAGE']['property_image_path'];
     $base_upload_dir = JPATH_ROOT . DS . $propertyImagePath;
     $validExtensions = array('jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'GIF', 'png', 'PNG', 'bmp', 'BMP');
     $i = 0;
     $secondImages = array();
     while (1) {
         $tempImage = JRequest::getVar($fieldName . $i, array(), 'files', 'array');
         if (!empty($tempImage)) {
             $secondImages[] = new Http_File($tempImage);
             $i++;
             echo " i = " . $i;
         } else {
             break;
         }
     }
     if (!JFolder::exists($base_upload_dir)) {
         JFolder::create($base_upload_dir);
     }
     $upload_dir = $base_upload_dir . DS . $id . DS . $folderName;
     $previewWidth = $u_reGlobalConfig['IMAGE']['image_width'];
     $thumbnailWidth = $u_reGlobalConfig['IMAGE']['thumbnail_width'];
     $thumbnailHeight = $u_reGlobalConfig['IMAGE']['thumbnail_height'];
     //default max height : 90px
     $largeWidth = $u_reGlobalConfig['IMAGE']['image_large_width'];
     $largeHeight = $u_reGlobalConfig['IMAGE']['image_large_height'];
     $jpgQuality = 90;
     $preview_dir = $upload_dir . DS . 'preview';
     $thumbnail_dir = $upload_dir . DS . 'min';
     $largeDir = $upload_dir . DS . 'large';
     if (!JFolder::exists($upload_dir)) {
         JFolder::create($upload_dir);
     }
     if (!JFolder::exists($preview_dir)) {
         JFolder::create($preview_dir);
     }
     if (!JFolder::exists($thumbnail_dir)) {
         JFolder::create($thumbnail_dir);
     }
     if (!JFolder::exists($largeDir)) {
         JFolder::create($largeDir);
     }
     foreach ($secondImages as $secondImage) {
         if ($secondImage->isPosted()) {
             $secondImage->setValidExtensions($validExtensions);
             $secondImage->nameToSafe();
             if (!($fileName = $secondImage->moveTo($upload_dir))) {
                 JError::raiseWarning(200, JText::_($secondImage->getError()));
                 return false;
             }
             //make preview
             U_ReModelProperties::_resizeImage($upload_dir . DS . $fileName, $preview_dir . DS . $fileName, null, $previewWidth, $jpgQuality);
             U_ReModelProperties::create_watermark($upload_dir . DS . $fileName, $upload_dir . DS . $fileName, $u_reGlobalConfig['WATERMARK']['image_preview_name'], $u_reGlobalConfig['WATERMARK']['image_path']);
             //make min
             U_ReModelProperties::_resizeImage($preview_dir . DS . $fileName, $thumbnail_dir . DS . $fileName, $thumbnailHeight, $thumbnailWidth, $jpgQuality);
             U_ReModelProperties::create_watermark($upload_dir . DS . $fileName, $upload_dir . DS . $fileName, $u_reGlobalConfig['WATERMARK']['image_name_min'], $u_reGlobalConfig['WATERMARK']['image_path']);
             // make large
             U_ReModelProperties::_resizeImage($preview_dir . DS . $fileName, $largeDir . DS . $fileName, $largeHeight, $largeWidth, $jpgQuality);
         }
     }
     // upload cac hinh anh dac biet: so do mat bang, noi that, ngoai that
     $i = 0;
     $sdmbImages = array();
     while (1) {
         $tempImage = JRequest::getVar('so_do_mat_bang_img' . $i, array(), 'files', 'array');
         if (!empty($tempImage)) {
             $sdmbImages[] = new Http_File($tempImage);
             $i++;
             echo " i = " . $i;
         } else {
             break;
         }
     }
     $upload_dir = $base_upload_dir . DS . $id;
     $upload_dir = $upload_dir . DS . 'sodomatbang';
     if (!JFolder::exists($upload_dir)) {
         JFolder::create($upload_dir);
     }
     $sdmbImages->setValidExtensions($validExtensions);
     $sdmbImages->nameToSafe();
     foreach ($sdmbImages as $sdmbImage) {
         if (!($fileName = $sdmbImage->moveTo($upload_dir))) {
             JError::raiseWarning(200, JText::_($sdmbImage->getError()));
             return false;
         }
         //make preview
         U_ReModelProperties::_resizeImage($upload_dir . DS . $fileName . '_preview', $preview_dir . DS . $fileName, null, $previewWidth, $jpgQuality);
         //make min
         U_ReModelProperties::_resizeImage($preview_dir . DS . $fileName, $thumbnail_dir . DS . $fileName, $thumbnailHeight, $thumbnailWidth, $jpgQuality);
         // make large
         U_ReModelProperties::_resizeImage($preview_dir . DS . $fileName, $largeDir . DS . $fileName, $largeHeight, $largeWidth, $jpgQuality);
     }
     return true;
 }