Пример #1
0
 public function upload_arhive()
 {
     global $_FILES;
     $allowedTypes = array("jpg", "jpeg", "gif", "bmp", "png");
     $referer = getRequest('referer');
     if (!$referer) {
         $referer = $_SERVER['HTTP_REFERER'];
     }
     $parentId = getRequest("parent_id");
     $hierarchy = umiHierarchy::getInstance();
     $element = $hierarchy->getElement($parentId);
     if (!$element) {
         throw new publicAdminException("Can't find parent album");
     }
     $altName = $element->getAltName();
     if (strlen($altName)) {
         $folder = "./images/cms/data/{$altName}/";
     } else {
         $folder = "./images/cms/data/";
     }
     $addWaterMark = (bool) getRequest("watermark");
     if (isset($_FILES['zip_arhive']) && is_uploaded_file($_FILES['zip_arhive']['tmp_name'])) {
         $originalName = $_FILES['zip_arhive']['name'];
         $extension = substr($originalName, strrpos($originalName, ".") + 1);
         if ($extension != "zip" && $file == "") {
             throw new publicAdminException("It's not arhive!");
         } else {
             $unzipedArray = umiFile::upload_zip($_FILES['zip_arhive'], "", $folder, $addWaterMark);
         }
         if (is_array($unzipedArray)) {
             foreach ($unzipedArray as $item) {
                 $file = $folder . basename($item['filename']);
                 $info = getPathInfo($file);
                 if (in_array(strtolower($info['extension']), $allowedTypes)) {
                     $this->addPhotoFromZip($file);
                 }
             }
             $this->redirect($referer);
             return;
         } else {
             throw new publicAdminException('Zip extracting error! ' . $unzipedArray);
         }
     }
     $file = getRequest('zip_arhive_src');
     if (!strlen($file)) {
         throw new publicAdminException(getLabel('zip-file-upload-error'));
     } else {
         $unzipedArray = umiFile::upload_zip("", $file, $folder, $addWaterMark);
         if (is_array($unzipedArray)) {
             foreach ($unzipedArray as $item) {
                 $file = $folder . basename($item['filename']);
                 $info = getPathInfo($file);
                 if (in_array(strtolower($info['extension']), $allowedTypes)) {
                     $this->addPhotoFromZip($file);
                 }
             }
             $this->redirect($referer);
         } else {
             throw new publicAdminException($unzipedArray);
         }
     }
 }