public function getThumb($width, $height) { $path = Yii::getPathOfAlias($this->path); $filePath = $path . DIRECTORY_SEPARATOR . 'thumb_' . $width . 'x' . $height . "_" . $this->name; $fileName = 'thumb_' . $width . 'x' . $height . "_" . $this->name; if (file_exists($filePath)) { return $fileName; } else { $image = new CImageHandler(); if ($image->load($path . DIRECTORY_SEPARATOR . $this->name)) { $image->thumb($width, $height)->save($filePath); return $fileName; } else { return null; } } }
public function actionUpload($id) { $model = $this->checkOwner($id); Yii::import("ext.EAjaxUpload.qqFileUploader"); $allowedExtensions = param('allowedImgExtensions', array('jpg', 'jpeg', 'gif', 'png')); //$sizeLimit = param('maxImgFileSize', 8 * 1024 * 1024); $sizeLimit = Images::getMaxSizeLimit(); $uploader = new qqFileUploader($allowedExtensions, $sizeLimit); $path = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::ORIGINAL_IMG_DIR); $pathMod = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::MODIFIED_IMG_DIR); $oldUMask = umask(0); if (!is_dir($path)) { @mkdir($path, 0777, true); } if (!is_dir($pathMod)) { @mkdir($pathMod, 0777, true); } umask($oldUMask); if (is_writable($path) && is_writable($pathMod)) { touch($path . DIRECTORY_SEPARATOR . 'index.htm'); touch($pathMod . DIRECTORY_SEPARATOR . 'index.htm'); $result = $uploader->handleUpload($path . DIRECTORY_SEPARATOR, false, uniqid()); if (isset($result['success']) && $result['success']) { $resize = new CImageHandler(); if ($resize->load($path . DIRECTORY_SEPARATOR . $result['filename'])) { $resize->thumb(param('maxImageWidth', 1024), param('maxImageHeight', 768), Images::KEEP_PHOTO_PROPORTIONAL)->save(); $image = new Images(); $image->id_object = $model->id; $image->id_owner = $model->owner_id; $image->file_name = $result['filename']; $image->save(); } else { $result['error'] = 'Wrong image type.'; @unlink($path . DIRECTORY_SEPARATOR . $result['filename']); } } } else { $result['error'] = 'Access denied.'; } // to pass data through iframe you will need to encode all html tags $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES); echo $result; }
public static function addImage($filePath, $objectId, $isMain, $ownerId) { $path = Yii::getPathOfAlias('webroot.uploads.objects.' . $objectId . '.' . Images::ORIGINAL_IMG_DIR); $pathMod = Yii::getPathOfAlias('webroot.uploads.objects.' . $objectId . '.' . Images::MODIFIED_IMG_DIR); $oldUMask = umask(0); if (!is_dir($path)) { @mkdir($path, 0777, true); } if (!is_dir($pathMod)) { @mkdir($pathMod, 0777, true); } umask($oldUMask); if (is_writable($path) && is_writable($pathMod)) { touch($path . DIRECTORY_SEPARATOR . 'index.htm'); touch($pathMod . DIRECTORY_SEPARATOR . 'index.htm'); $ext = $ext = pathinfo($filePath, PATHINFO_EXTENSION); $mewFName = md5($filePath) . '.' . $ext; $newFilePath = $path . DIRECTORY_SEPARATOR . $mewFName; $resize = new CImageHandler(); echo $filePath . '<br/>'; if ($resize->load($filePath)) { $resize->thumb(param('maxImageWidth', 1024), param('maxImageHeight', 768), Images::KEEP_PHOTO_PROPORTIONAL)->save($newFilePath); $image = new Images(); $image->id_object = $objectId; $image->id_owner = $ownerId; $image->is_main = $isMain; $image->file_name = $mewFName; $image->save(); } else { echo $newFilePath . ': Wrong image type.<br/>'; @unlink($newFilePath); } } }
/** * Copy image from temporary folder to proper destination and create thumbnails */ protected function saveImage() { $imageHandler = new CImageHandler(); $imageHandler->load($this->getTempFolder(TRUE) . $this->image); $imageHandler->save($this->getImagesFolder(TRUE) . $imageHandler->getBaseFileName()); $settings = $this->getThumbsSettings(); if (!empty($settings)) { $imageHandler = new CImageHandler(); $imageHandler->load($this->getTempFolder(TRUE) . $this->image); foreach ($settings as $prefix => $dimensions) { list($width, $height) = $dimensions; $imageHandler->thumb($width, $height)->save($this->getImagesFolder(TRUE) . $prefix . $imageHandler->getBaseFileName()); } } }
public function actionUpload($id) { $model = $this->checkOwner($id); $maxImgs = 0; # unlimited $currImgCount = 0; if (issetModule('tariffPlans') && issetModule('paidservices')) { $sql = 'SELECT COUNT(id) FROM {{images}} WHERE id_object = ' . $model->id; $currImgCount = Yii::app()->db->createCommand($sql)->queryScalar(); $userTariffInfo = TariffPlans::getTariffInfoByUserId($model->owner_id); $maxImgs = $userTariffInfo['limitPhotos']; if (Yii::app()->user->checkAccess("backend_access")) { # admin or moderator $maxImgs = 0; } } if ($maxImgs > 0 && $currImgCount >= $maxImgs) { $result['error'] = Yii::t("module_tariffPlans", "You are trying to download more than {num} pictures ( your tariff limit )", array("{num}" => $maxImgs)); $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES); echo $result; Yii::app()->end(); } Yii::import("ext.EAjaxUpload.qqFileUploader"); $allowedExtensions = param('allowedImgExtensions', array('jpg', 'jpeg', 'gif', 'png')); //$sizeLimit = param('maxImgFileSize', 8 * 1024 * 1024); $sizeLimit = Images::getMaxSizeLimit(); $uploader = new qqFileUploader($allowedExtensions, $sizeLimit); $path = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::ORIGINAL_IMG_DIR); $pathMod = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::MODIFIED_IMG_DIR); $oldUMask = umask(0); if (!is_dir($path)) { @mkdir($path, 0777, true); } if (!is_dir($pathMod)) { @mkdir($pathMod, 0777, true); } umask($oldUMask); if (is_writable($path) && is_writable($pathMod)) { touch($path . DIRECTORY_SEPARATOR . 'index.htm'); touch($pathMod . DIRECTORY_SEPARATOR . 'index.htm'); $result = $uploader->handleUpload($path . DIRECTORY_SEPARATOR, false, uniqid()); if (isset($result['success']) && $result['success']) { $resize = new CImageHandler(); if ($resize->load($path . DIRECTORY_SEPARATOR . $result['filename'])) { $resize->thumb(param('maxImageWidth', 1024), param('maxImageHeight', 768), Images::KEEP_PHOTO_PROPORTIONAL)->save(); $image = new Images(); $image->id_object = $model->id; $image->id_owner = $model->owner_id; $image->file_name = $result['filename']; if ($image->save() && $model->hasAttribute('count_img')) { $model->count_img++; $model->update('count_img'); } } else { $result['error'] = 'Wrong image type.'; @unlink($path . DIRECTORY_SEPARATOR . $result['filename']); } } } else { $result['error'] = 'Access denied.'; } // to pass data through iframe you will need to encode all html tags $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES); echo $result; }
private function addListingFromCSV($value, $isZip, $maxSorter, $selectedImportUser) { if (is_array($value)) { $model = new $this->modelName(); $type = !empty($value['type']) ? $value['type'] : Apartment::TYPE_DEFAULT; $priceType = !empty($value['priceType']) ? $value['priceType'] : ''; $objType = !empty($value['objType']) ? $value['objType'] : min(Apartment::getObjTypesArray()); $countryName = !empty($value['countryName']) ? trim($value['countryName']) : null; $regionName = !empty($value['regionName']) ? trim($value['regionName']) : null; $cityName = !empty($value['cityName']) ? trim($value['cityName']) : null; $countryId = $countryInfo = $regionId = $regionInfo = $cityId = $cityInfo = 0; if (issetModule('location')) { if ($countryName) { if (isFree()) { $countryInfo = Country::model()->findByAttributes(array('name_' . Yii::app()->language => $countryName)); } else { Yii::app()->setLanguage($this->defLang); $countryInfo = Country::model()->findByAttributes(array('name_' . Yii::app()->language => $countryName)); Yii::app()->setLanguage($this->currLang); } if ($countryInfo && isset($countryInfo->id)) { $countryId = $countryInfo->id; } } if ($regionName) { if (isFree()) { $regionInfo = Region::model()->findByAttributes(array('name_' . Yii::app()->language => $regionName)); } else { Yii::app()->setLanguage($this->defLang); $regionInfo = Region::model()->findByAttributes(array('name_' . Yii::app()->language => $regionName)); Yii::app()->setLanguage($this->currLang); } if ($regionInfo && isset($regionInfo->id)) { $regionId = $regionInfo->id; } } if ($cityName) { if (isFree()) { $cityInfo = City::model()->findByAttributes(array('name_' . Yii::app()->language => $cityName)); } else { Yii::app()->setLanguage($this->defLang); $cityInfo = City::model()->findByAttributes(array('name_' . Yii::app()->language => $cityName)); Yii::app()->setLanguage($this->currLang); } if ($cityInfo && isset($cityInfo->id)) { $cityId = $cityInfo->id; } } } else { if ($cityName) { Yii::import('application.modules.apartmentCity.models.ApartmentCity'); if (isFree()) { $cityInfo = ApartmentCity::model()->findByAttributes(array('name_' . Yii::app()->language => $cityName)); } else { Yii::app()->setLanguage($this->defLang); $cityInfo = ApartmentCity::model()->findByAttributes(array('name_' . Yii::app()->language => $cityName)); Yii::app()->setLanguage($this->currLang); } if ($cityInfo && isset($cityInfo->id)) { $cityId = $cityInfo->id; } } } // if type for sale - set price type only for sale if ($type == Apartment::TYPE_SALE) { $priceType = Apartment::PRICE_SALE; } $isPricePoa = isset($value['isPricePoa']) ? $value['isPricePoa'] : 0; $price = !empty($value['price']) ? $value['price'] : ''; $priceTo = !empty($value['priceTo']) ? $value['priceTo'] : ''; $numberRooms = !empty($value['numberRooms']) ? $value['numberRooms'] : ''; $floor = !empty($value['floor']) ? $value['floor'] : ''; $floor_total = !empty($value['floorTotal']) ? $value['floorTotal'] : ''; $square = !empty($value['square']) ? $value['square'] : ''; $landSquare = !empty($value['landSquare']) ? $value['landSquare'] : ''; $sleeps = !empty($value['sleeps']) ? $this->deleteChars($value['sleeps']) : ''; if (isFree()) { $title = !empty($value['title']) ? $this->deleteChars($value['title']) : ''; $description = !empty($value['description']) ? $this->deleteChars($value['description']) : ''; $near = !empty($value['near']) ? $this->deleteChars($value['near']) : ''; $address = !empty($value['location']) ? $this->deleteChars($value['location']) : ''; $exchange = !empty($value['exchange']) ? $this->deleteChars($value['exchange']) : ''; } else { if ($this->allLangs) { foreach ($this->i18nMaskFields as $i18nMaskField) { foreach ($this->allLangs as $lang) { $title[$lang->name_iso] = $this->deleteChars($value['title_' . $lang->name_iso]); $description[$lang->name_iso] = $this->deleteChars($value['description_' . $lang->name_iso]); $near[$lang->name_iso] = $this->deleteChars($value['near_' . $lang->name_iso]); $address[$lang->name_iso] = $this->deleteChars($value['location_' . $lang->name_iso]); $exchange[$lang->name_iso] = $this->deleteChars($value['exchange_' . $lang->name_iso]); } } } } $lat = !empty($value['lat']) ? $value['lat'] : ''; $lng = !empty($value['lng']) ? $value['lng'] : ''; // references $adRef = array(); $adRef['bathroom'] = !empty($value['bathroom']) ? explode($this->separatorElem, $value['bathroom']) : null; $adRef['safety'] = !empty($value['safety']) ? explode($this->separatorElem, $value['safety']) : null; $adRef['comfort'] = !empty($value['comfort']) ? explode($this->separatorElem, $value['comfort']) : null; $adRef['kitchen'] = !empty($value['kitchen']) ? explode($this->separatorElem, $value['kitchen']) : null; $adRef['employment'] = !empty($value['employment']) ? explode($this->separatorElem, $value['employment']) : null; $adRef['entertainment'] = !empty($value['entertainment']) ? explode($this->separatorElem, $value['entertainment']) : null; $adRef['services'] = !empty($value['services']) ? explode($this->separatorElem, $value['services']) : null; $adRef['terms'] = !empty($value['terms']) ? explode($this->separatorElem, $value['terms']) : null; $photos = !empty($value['photos']) ? explode($this->separatorElem, $value['photos']) : null; // insert into apartments table if (isFree()) { $sql = 'INSERT INTO {{apartment}} (type, obj_type_id, loc_country, loc_region, loc_city, city_id, date_updated, date_created, activity_always, is_price_poa, price, price_to, num_of_rooms, floor, floor_total, square, land_square, window_to, title_' . Yii::app()->language . ', description_' . Yii::app()->language . ', description_near_' . Yii::app()->language . ', exchange_to_' . Yii::app()->language . ', living_conditions, services, address_' . Yii::app()->language . ', berths, active, lat, lng, rating, is_special_offer, is_free_to, price_type, sorter, owner_active, owner_id) VALUES (:type, :objType, :locCountryId, :locRegionId, :locCityId, :cityId, NOW(), NOW(), :activityAlways, :isPricePoa, :price, :priceTo,:numberRooms, :floor, :floorTotal, :square, :landSquare, :windowTo, :title, :description, :descriptionNear, :exchangeTo, :livingConditions, :services, :address, :berths, :active, :lat, :lng, :rating, "", "", :priceType, :maxSorter, :ownerActive, :ownerId) '; $command = Yii::app()->db->createCommand($sql); $command->bindValue(":type", $type, PDO::PARAM_INT); $command->bindValue(":objType", $objType, PDO::PARAM_INT); $command->bindValue(":locCountryId", $countryId, PDO::PARAM_INT); $command->bindValue(":locRegionId", $regionId, PDO::PARAM_INT); $command->bindValue(":locCityId", $cityId, PDO::PARAM_INT); $command->bindValue(":cityId", $cityId, PDO::PARAM_INT); $command->bindValue(":activityAlways", 1, PDO::PARAM_INT); $command->bindValue(":isPricePoa", $isPricePoa, PDO::PARAM_INT); $command->bindValue(":price", $price, PDO::PARAM_STR); $command->bindValue(":priceTo", $priceTo, PDO::PARAM_STR); $command->bindValue(":numberRooms", $numberRooms, PDO::PARAM_INT); $command->bindValue(":floor", $floor, PDO::PARAM_INT); $command->bindValue(":floorTotal", $floor_total, PDO::PARAM_INT); $command->bindValue(":square", $square, PDO::PARAM_INT); $command->bindValue(":landSquare", $landSquare, PDO::PARAM_INT); $command->bindValue(":windowTo", 0, PDO::PARAM_INT); $command->bindValue(":title", $title, PDO::PARAM_STR); $command->bindValue(":description", $description, PDO::PARAM_STR); $command->bindValue(":descriptionNear", $near, PDO::PARAM_STR); $command->bindValue(":exchangeTo", $exchange, PDO::PARAM_STR); $command->bindValue(":livingConditions", 0, PDO::PARAM_INT); $command->bindValue(":services", 0, PDO::PARAM_INT); $command->bindValue(":address", $address, PDO::PARAM_STR); $command->bindValue(":berths", $sleeps, PDO::PARAM_STR); $command->bindValue(":active", 0, PDO::PARAM_INT); $command->bindValue(":lat", $lat, PDO::PARAM_STR); $command->bindValue(":lng", $lng, PDO::PARAM_STR); $command->bindValue(":rating", 0, PDO::PARAM_INT); $command->bindValue(":priceType", $priceType, PDO::PARAM_INT); $command->bindValue(":maxSorter", $maxSorter, PDO::PARAM_INT); $command->bindValue(":ownerActive", 1, PDO::PARAM_INT); $command->bindValue(":ownerId", $selectedImportUser, PDO::PARAM_INT); $command->execute(); $lastId = Yii::app()->db->getLastInsertID(); } else { $fieldsSQL = $placeholdersSQL = $valuesSQL = array(); if ($this->allLangs) { foreach ($this->allLangs as $lang) { $fieldsSQL[] = 'title_' . $lang->name_iso; $fieldsSQL[] = 'description_' . $lang->name_iso; $fieldsSQL[] = 'description_near_' . $lang->name_iso; $fieldsSQL[] = 'address_' . $lang->name_iso; $fieldsSQL[] = 'exchange_to_' . $lang->name_iso; $placeholdersSQL[] = ':title_' . $lang->name_iso; $placeholdersSQL[] = ':description_' . $lang->name_iso; $placeholdersSQL[] = ':description_near_' . $lang->name_iso; $placeholdersSQL[] = ':address_' . $lang->name_iso; $placeholdersSQL[] = ':exchange_to_' . $lang->name_iso; $valuesSQL[':title_' . $lang->name_iso] = $this->deleteChars($title[$lang->name_iso]); $valuesSQL[':description_' . $lang->name_iso] = $this->deleteChars($description[$lang->name_iso]); $valuesSQL[':description_near_' . $lang->name_iso] = $this->deleteChars($near[$lang->name_iso]); $valuesSQL[':address_' . $lang->name_iso] = $this->deleteChars($address[$lang->name_iso]); $valuesSQL[':exchange_to_' . $lang->name_iso] = $this->deleteChars($exchange[$lang->name_iso]); } } $sql = 'INSERT INTO {{apartment}} ( type, obj_type_id, loc_country, loc_region, loc_city, city_id, date_updated, date_created, activity_always, is_price_poa, price, price_to, num_of_rooms, floor, floor_total, square, land_square, window_to, living_conditions, services, berths, active, lat, lng, rating, is_special_offer, is_free_to, price_type, sorter, owner_active, owner_id, ' . implode(", ", $fieldsSQL) . ' ) VALUES ( :type, :objType, :locCountryId, :locRegionId, :locCityId, :cityId, NOW(), NOW(), :activityAlways, :isPricePoa, :price, :priceTo,:numberRooms, :floor, :floorTotal, :square, :landSquare, :windowTo, :livingConditions, :services, :berths, :active, :lat, :lng, :rating, "", "", :priceType, :maxSorter, :ownerActive, :ownerId, ' . implode(", ", $placeholdersSQL) . ' ) '; $command = Yii::app()->db->createCommand($sql); $command->bindValue(":type", $type, PDO::PARAM_INT); $command->bindValue(":objType", $objType, PDO::PARAM_INT); $command->bindValue(":locCountryId", $countryId, PDO::PARAM_INT); $command->bindValue(":locRegionId", $regionId, PDO::PARAM_INT); $command->bindValue(":locCityId", $cityId, PDO::PARAM_INT); $command->bindValue(":cityId", $cityId, PDO::PARAM_INT); $command->bindValue(":activityAlways", 1, PDO::PARAM_INT); $command->bindValue(":isPricePoa", $isPricePoa, PDO::PARAM_INT); $command->bindValue(":price", $price, PDO::PARAM_STR); $command->bindValue(":priceTo", $priceTo, PDO::PARAM_STR); $command->bindValue(":numberRooms", $numberRooms, PDO::PARAM_INT); $command->bindValue(":floor", $floor, PDO::PARAM_INT); $command->bindValue(":floorTotal", $floor_total, PDO::PARAM_INT); $command->bindValue(":square", $square, PDO::PARAM_INT); $command->bindValue(":landSquare", $landSquare, PDO::PARAM_INT); $command->bindValue(":windowTo", 0, PDO::PARAM_INT); $command->bindValue(":livingConditions", 0, PDO::PARAM_INT); $command->bindValue(":services", 0, PDO::PARAM_INT); $command->bindValue(":berths", $sleeps, PDO::PARAM_STR); $command->bindValue(":active", 0, PDO::PARAM_INT); $command->bindValue(":lat", $lat, PDO::PARAM_STR); $command->bindValue(":lng", $lng, PDO::PARAM_STR); $command->bindValue(":rating", 0, PDO::PARAM_INT); $command->bindValue(":priceType", $priceType, PDO::PARAM_INT); $command->bindValue(":maxSorter", $maxSorter, PDO::PARAM_INT); $command->bindValue(":ownerActive", 1, PDO::PARAM_INT); $command->bindValue(":ownerId", $selectedImportUser, PDO::PARAM_INT); foreach ($valuesSQL as $name => $value) { $command->bindValue($name, $value, PDO::PARAM_STR); } $command->execute(); $lastId = Yii::app()->db->getLastInsertID(); } // insert references foreach ($adRef as $key => $value) { switch ($key) { case 'comfort': $refId = 1; break; case 'bathroom': $refId = 2; break; case 'kitchen': $refId = 3; break; case 'employment': $refId = 4; break; case 'safety': $refId = 5; break; case 'entertainment': $refId = 7; break; case 'terms': $refId = 9; break; case 'services': $refId = 10; break; } if (is_array($value) && count($value) > 0) { foreach ($value as $item) { // get reference id by name if (isFree()) { //$sql = "SELECT id FROM {{apartment_reference_values}} WHERE title_" . Yii::app()->language . " = '" . $item . "' AND reference_category_id = '" . $refId . "'"; //$valId = Yii::app()->db->createCommand($sql)->queryRow(); $valId = Yii::app()->db->createCommand()->select('id')->from('{{apartment_reference_values}}')->where('title_' . Yii::app()->language . ' = :title AND reference_category_id = :catId', array(':title' => $item, ':catId' => $refId))->queryRow(); } else { Yii::app()->setLanguage($this->defLang); //$sql = "SELECT id FROM {{apartment_reference_values}} WHERE title_" . Yii::app()->language . " = '" . $item . "' AND reference_category_id = '" . $refId . "'"; //$valId = Yii::app()->db->createCommand($sql)->queryRow(); $valId = Yii::app()->db->createCommand()->select('id')->from('{{apartment_reference_values}}')->where('title_' . Yii::app()->language . ' = :title AND reference_category_id = :catId', array(':title' => $item, ':catId' => $refId))->queryRow(); Yii::app()->setLanguage($this->currLang); } if (isset($valId['id']) && !empty($valId['id'])) { $sql = 'INSERT INTO {{apartment_reference}} (reference_id, reference_value_id, apartment_id) VALUES (:refId, :refValId, :apId) '; $command = Yii::app()->db->createCommand($sql); $command->bindValue(":refId", $refId, PDO::PARAM_INT); $command->bindValue(":refValId", $valId['id'], PDO::PARAM_INT); $command->bindValue(":apId", $lastId, PDO::PARAM_INT); $command->execute(); } } } } // get and upload photos if (is_array($photos) && count($photos) > 0) { $arrFiles = $arrImgs = array(); $IecsvFiles = array(); foreach ($photos as $key => $item) { if (!$isZip) { if (stristr($item, "http")) { $pathParts = pathinfo($item); $file = $pathParts['basename']; $fileExt = $pathParts['extension']; $photoPath = $model->csvPath . DIRECTORY_SEPARATOR . $file; // get file by cUrl if (function_exists('curl_version')) { $ch = curl_init(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $item); $fp = fopen($photoPath, 'wb'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); } else { // no CUrl, try differently file_put_contents($photoPath, file_get_contents($item)); } // reset file name - remove host. only filename and extension. $item = $file; } } else { // image from zip arhive $photoPath = $model->csvPath . DIRECTORY_SEPARATOR . $item; } if (file_exists($photoPath)) { $IecsvFiles[$key]['name'] = $item; $IecsvFiles[$key]['tmp_name'] = $photoPath; } } if (count($IecsvFiles) > 0) { $apartment = Apartment::model()->findByPk($lastId); $path = Yii::getPathOfAlias('webroot.uploads.objects.' . $apartment->id . '.' . Images::ORIGINAL_IMG_DIR); $pathMod = Yii::getPathOfAlias('webroot.uploads.objects.' . $apartment->id . '.' . Images::MODIFIED_IMG_DIR); $oldUMask = umask(0); if (!is_dir($path)) { @mkdir($path, 0777, true); } if (!is_dir($pathMod)) { @mkdir($pathMod, 0777, true); } umask($oldUMask); $result['error'] = ''; if (is_writable($path) && is_writable($pathMod)) { touch($path . DIRECTORY_SEPARATOR . 'index.htm'); touch($pathMod . DIRECTORY_SEPARATOR . 'index.htm'); foreach ($IecsvFiles as $IecsvFile) { if (copy($model->csvPath . DIRECTORY_SEPARATOR . $IecsvFile['name'], $path . DIRECTORY_SEPARATOR . $IecsvFile['name'])) { $resize = new CImageHandler(); if ($resize->load($path . DIRECTORY_SEPARATOR . $IecsvFile['name'])) { $resize->thumb(param('maxImageWidth', 1024), param('maxImageHeight', 768), Images::KEEP_PHOTO_PROPORTIONAL)->save(); $image = new Images(); $image->id_object = $apartment->id; $image->id_owner = $apartment->owner_id; $image->file_name = $IecsvFile['name']; $image->save(); } } else { $result['error'] = 'No copy'; } } } else { $result['error'] = 'Access denied.'; } } } } }