コード例 #1
0
ファイル: File.php プロジェクト: grrr-amsterdam/garp3
 /**
  * @param Boolean $returnNonImageExtensions Whether to return only non-image extensions, or all uploadable extensions.
  * @return Array List of uploadable extensions
  */
 public function getAllowedExtensions()
 {
     $ini = $this->_getIni();
     $extensions = explode(',', $ini->cdn->extensions);
     $imageFile = new Garp_Image_File($this->_uploadOrStatic);
     $imageExtensions = $imageFile->getAllowedExtensions();
     $extensions = array_filter($extensions, function ($element) use($imageExtensions) {
         return !in_array($element, $imageExtensions);
     });
     return $extensions;
 }
コード例 #2
0
 /**
  * /g/content/download-zipped/dinges.pdf,jadda.gif/myZipArchiveName
  *
  * @return Void
  */
 public function downloadzippedAction()
 {
     $params = $this->getRequest()->getParams();
     if (!array_key_exists('files', $params) || !array_key_exists('zipname', $params) || !$params['files'] || !$params['zipname']) {
         throw new Exception('Please provide a filename list, and a name for the archive.');
     }
     $zip = new ZipArchive();
     $tmpDir = sys_get_temp_dir();
     $tmpDir .= $tmpDir[strlen($tmpDir) - 1] !== '/' ? '/' : '';
     $zipPath = $tmpDir . $params['zipname'] . '.zip';
     if ($zip->open($zipPath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
         throw new Exception("Cannot open <{$zipPath}>\n");
     }
     //  @todo: als cdn niet lokaal is, moet je waarschijnlijk met zip::addFromString werken.
     $filenames = explode(',', $params['files']);
     $image = new Garp_Image_File(Garp_File::FILE_VARIANT_UPLOAD);
     $document = new Garp_File(null, Garp_File::FILE_VARIANT_UPLOAD);
     $ini = Zend_Registry::get('config');
     $cdnIsLocal = $ini->cdn->type === "local";
     foreach ($filenames as $filename) {
         $allowedImageExtensions = $image->getAllowedExtensions();
         $filenameParts = explode('.', $filename);
         $extension = $filenameParts[count($filenameParts) - 1];
         $fileIsImage = in_array($extension, $allowedImageExtensions);
         $file = $fileIsImage ? $image : $document;
         $url = $file->getUrl($filename);
         if ($content = @file_get_contents($url)) {
             $zip->addFromString('/' . $params['zipname'] . '/' . $filename, $content);
         } else {
             throw new Exception("{$url} could not be opened for inclusion in the zip archive.");
         }
     }
     $zip->close();
     $this->_downloadFile($zipPath);
     @unlink($zipPath);
 }