Beispiel #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 = \Nette\Environment::getHttpResponse();
     $req = \Nette\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);
     }
 }
Beispiel #2
0
 /**
  * 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;
 }
Beispiel #3
0
 /**
  * Download the file!
  * @param IDownloader $downloader
  */
 function download(IDownloader $downloader = null)
 {
     $req = \Nette\Environment::getHttpRequest();
     $res = \Nette\Environment::getHttpResponse();
     if (self::$closeSession) {
         $ses = \Nette\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 \Nette\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 \Nette\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(\Nette\Environment::getHttpResponse(), TRUE);
         throw $lastException;
     }
     if ($req->getHeader("Range")) {
         FDTools::_HTTPError(416);
     } else {
         $res->setCode(500);
     }
     throw new \Nette\InvalidStateException("There is no compatible downloader (all downloader returns downloader->isComplatible()=false or was skipped)!");
 }