Ejemplo n.º 1
0
 public function runGetFile(framework\Request $request)
 {
     $file = new entities\File((int) $request['id']);
     if ($file instanceof entities\File) {
         if ($file->hasAccess()) {
             $disableCache = true;
             $isFile = false;
             $this->getResponse()->cleanBuffer();
             $this->getResponse()->clearHeaders();
             $this->getResponse()->setDecoration(\thebuggenie\core\framework\Response::DECORATE_NONE);
             if ($file->isImage() && \thebuggenie\core\framework\Settings::isUploadsImageCachingEnabled()) {
                 $this->getResponse()->addHeader('Pragma: public');
                 $this->getResponse()->addHeader('Cache-Control: public, max-age: 15768000');
                 $this->getResponse()->addHeader("Expires: " . gmdate('D, d M Y H:i:s', time() + 15768000) . " GMT");
                 $disableCache = false;
             }
             $this->getResponse()->addHeader('Content-disposition: ' . ($request['mode'] == 'download' ? 'attachment' : 'inline') . '; filename="' . $file->getOriginalFilename() . '"');
             $this->getResponse()->setContentType($file->getContentType());
             if (framework\Settings::getUploadStorage() == 'files') {
                 $fh = fopen(framework\Settings::getUploadsLocalpath() . $file->getRealFilename(), 'r');
                 $isFile = true;
             } else {
                 $fh = $file->getContent();
             }
             if (is_resource($fh)) {
                 if ($isFile && \thebuggenie\core\framework\Settings::isUploadsDeliveryUseXsend()) {
                     $this->getResponse()->addHeader('X-Sendfile: ' . framework\Settings::getUploadsLocalpath() . $file->getRealFilename());
                     $this->getResponse()->addHeader('X-Accel-Redirect: /files/' . $file->getRealFilename());
                     $this->getResponse()->renderHeaders($disableCache);
                 } else {
                     $this->getResponse()->renderHeaders($disableCache);
                     fpassthru($fh);
                 }
             } else {
                 $this->getResponse()->renderHeaders($disableCache);
                 echo $fh;
             }
             exit;
         }
     }
     $this->return404(framework\Context::getI18n()->__('This file does not exist'));
 }
Ejemplo n.º 2
0
 public function runGetFile(framework\Request $request)
 {
     $file = new entities\File((int) $request['id']);
     if ($file instanceof entities\File) {
         if ($file->hasAccess()) {
             $this->getResponse()->cleanBuffer();
             $this->getResponse()->clearHeaders();
             $this->getResponse()->setDecoration(\thebuggenie\core\framework\Response::DECORATE_NONE);
             $this->getResponse()->addHeader('Content-disposition: ' . ($request['mode'] == 'download' ? 'attachment' : 'inline') . '; filename="' . $file->getOriginalFilename() . '"');
             $this->getResponse()->setContentType($file->getContentType());
             $this->getResponse()->renderHeaders();
             if (framework\Settings::getUploadStorage() == 'files') {
                 fpassthru(fopen(framework\Settings::getUploadsLocalpath() . $file->getRealFilename(), 'r'));
                 exit;
             } else {
                 echo $file->getContent();
                 exit;
             }
         }
     }
     $this->return404(framework\Context::getI18n()->__('This file does not exist'));
 }