コード例 #1
0
 /**
  * Sends a standard headers for file download
  * @param BaseFileDownload $file            File
  * @param BaseDownloader $downloader    Downloader of the file
  */
 protected function sendStandardFileHeaders(BaseFileDownload $file, BaseDownloader $downloader = null)
 {
     $res = Environment::getHttpResponse();
     $req = Environment::getHttpRequest();
     //FDTools::clearHeaders($res); // Voláno už v FileDownload.php
     $res->setContentType($file->mimeType, "UTF-8");
     $res->setHeader("X-File-Downloader", "File Downloader (http://filedownloader.projekty.mujserver.net)");
     if ($downloader !== null) {
         $res->setHeader("X-FileDownloader-Actual-Script", $downloader->getReflection()->name);
     }
     $res->setHeader('Pragma', 'public');
     // Fix for IE - Content-Disposition
     $res->setHeader('Content-Disposition', $file->getContentDisposition() . '; filename="' . FDTools::getContentDispositionHeaderData($file->transferFileName) . '"');
     $res->setHeader('Content-Description', 'File Transfer');
     $res->setHeader('Content-Transfer-Encoding', 'binary');
     $res->setHeader('Connection', 'close');
     $res->setHeader('ETag', FDTools::getETag($file->sourceFile));
     $res->setHeader('Content-Length', FDTools::filesize($file->sourceFile));
     // Cache control
     if ($file->enableBrowserCache) {
         $this->setupCacheHeaders($file);
     } else {
         $this->setupNonCacheHeaders($file);
     }
 }
コード例 #2
0
ファイル: BaseFileDownload.php プロジェクト: OCC2/occ2pacs
 /**
  * Download the file!
  * @param IDownloader $downloader
  */
 function download(IDownloader $downloader = null)
 {
     $req = Environment::getHttpRequest();
     $res = Environment::getHttpResponse();
     if (self::$closeSession) {
         $ses = Environment::getSession();
         if ($ses->isStarted()) {
             $ses->close();
         }
     }
     if ($this->getContentDisposition() == "inline" and is_null($this->enableBrowserCache)) {
         $this->enableBrowserCache = true;
     } else {
         $this->enableBrowserCache = false;
     }
     if ($downloader === null) {
         $downloaders = self::getFileDownloaders();
     } else {
         $downloaders = array($downloader);
     }
     if (count($downloaders) <= 0) {
         throw new InvalidStateException("There is no registred downloader!");
     }
     krsort($downloaders);
     $lastException = null;
     foreach ($downloaders as $downloader) {
         if ($downloader instanceof IDownloader and $downloader->isCompatible($this)) {
             try {
                 FDTools::clearHeaders($res);
                 // Delete all headers
                 $this->transferredBytes = 0;
                 $this->onBeforeDownloaderStarts($this, $downloader);
                 $downloader->download($this);
                 // Start download
                 $this->onComplete($this, $downloader);
                 die;
                 // If all gone ok -> die
             } catch (FDSkypeMeException $e) {
                 if ($res->isSent()) {
                     throw new InvalidStateException("Headers are already sent! Can't skip downloader.");
                 } else {
                     continue;
                 }
             } catch (Exception $e) {
                 if (!$res->isSent()) {
                     FDTools::clearHeaders($res);
                 }
                 throw $e;
             }
         }
     }
     // Pokud se soubor nějakým způsobem odešle - toto už se nespustí
     if ($lastException instanceof Exception) {
         FDTools::clearHeaders(Environment::getHttpResponse(), TRUE);
         throw $lastException;
     }
     if ($req->getHeader("Range")) {
         FDTools::_HTTPError(416);
     } else {
         $res->setCode(500);
     }
     throw new InvalidStateException("There is no compatible downloader (all downloader returns downloader->isComplatible()=false or was skipped)!");
 }
コード例 #3
0
ファイル: AdvancedDownloader.php プロジェクト: OCC2/occ2pacs
 /**
  * Is this downloader compatible?
  * @param BaseFileDownload $file
  * @return bool TRUE if is compatible; FALSE if not
  */
 function isCompatible(BaseFileDownload $file)
 {
     if (self::$checkEnvironmentSettings === true) {
         if (FDTools::setTimeLimit(0) !== true) {
             return false;
         }
     }
     return true;
 }