コード例 #1
0
ファイル: Fm.php プロジェクト: rbraband/sefrengo
 /**
  * Forces the preview of a single file by id
  * (retrieve from {@link $req}) and exits the script.
  * Works similar to downloadFile().
  * @return void
  */
 public function previewFile()
 {
     //get id
     $id = (int) $this->req->req('id', 0);
     $thumb = (int) $this->req->req('thumb', -1);
     //load data - if loading fails redirect to index page
     if (!$this->file_sql_item->loadById($id)) {
         $this->_setSystemLogMessage('file_is_not_loaded', array('id' => $id));
         return $this->lng->get($this->config_area['area_name'] . '_error_file_is_not_loaded');
     }
     // check perm for action
     if ($this->file_sql_item->hasPerm('view') == FALSE) {
         $this->_setUserLogMessage('permission_denied', array('id' => $id, 'path' => $this->file_sql_item->getRelativePath()), 'debug');
         $this->_indexRedirect('error_permission_denied');
     }
     $fsm = sf_api('LIB', 'FilesystemManipulation');
     $extension = $fsm->getPathinfo($path, 'extension');
     $path = $this->file_sql_item->getPath();
     // Get thumbnail if wanted and possible
     if ($thumb > -1 && $this->file_sql_item instanceof SF_MODEL_FileSqlItem && $this->file_sql_item->isThumbnailGenerationPossible() == TRUE) {
         $thumbdata = $this->file_sql_item->getThumbnails($thumb);
         if (array_key_exists('path', $thumbdata) == TRUE) {
             $path = $thumbdata['path'];
         }
     }
     $dl = sf_api('LIB', 'Download');
     $dl->forceByPath($path, array('content-disposition' => 'inline'));
 }