Пример #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'));
 }