Beispiel #1
0
 public function runGetFile(TBGRequest $request)
 {
     $file = new TBGFile((int) $request['id']);
     if ($file instanceof TBGFile) {
         if ($file->hasAccess()) {
             $this->getResponse()->cleanBuffer();
             $this->getResponse()->clearHeaders();
             $this->getResponse()->setDecoration(TBGResponse::DECORATE_NONE);
             $this->getResponse()->addHeader('Content-disposition: ' . ($request['mode'] == 'download' ? 'attachment' : 'inline') . '; filename="' . $file->getOriginalFilename() . '"');
             $this->getResponse()->setContentType($file->getContentType());
             $this->getResponse()->renderHeaders();
             if (TBGSettings::getUploadStorage() == 'files') {
                 fpassthru(fopen(TBGSettings::getUploadsLocalpath() . $file->getRealFilename(), 'r'));
                 exit;
             } else {
                 echo $file->getContent();
                 exit;
             }
             return true;
         }
     }
     $this->return404(TBGContext::getI18n()->__('This file does not exist'));
 }
Beispiel #2
0
 /**
  * Attach a file to the issue
  * 
  * @param TBGFile $file The file to attach
  */
 public function attachFile(TBGFile $file, $file_comment = '', $description = '')
 {
     $existed = !TBGIssueFilesTable::getTable()->addByIssueIDandFileID($this->getID(), $file->getID());
     if (!$existed) {
         $comment = new TBGComment();
         $comment->setPostedBy(TBGContext::getUser()->getID());
         $comment->setTargetID($this->getID());
         $comment->setTargetType(TBGComment::TYPE_ISSUE);
         if ($file_comment) {
             $comment->setContent(TBGContext::getI18n()->__('A file was uploaded. %link_to_file This comment was attached: %comment', array('%comment' => "\n\n" . $file_comment, '%link_to_file' => "[[File:{$file->getOriginalFilename()}|thumb|{$description}]]")));
         } else {
             $comment->setContent(TBGContext::getI18n()->__('A file was uploaded. %link_to_file', array('%link_to_file' => "[[File:{$file->getOriginalFilename()}|thumb|{$description}]]")));
         }
         $comment->save();
         if ($this->_files !== null) {
             $this->_files[$file->getID()] = $file;
         }
     }
 }