Esempio n. 1
0
File: file.php Progetto: Jintha/cama
 /**
  * Load the file and feed it to the user's browser (after registering a hit).  Execution is halted
  *
  * @param DH_Hole $hole Hole in which the file lives
  **/
 function download($hole, $version = '')
 {
     // Is this a local or a remote file?
     $download_as = $this->download_as(true);
     if (strpos($download_as, '://') !== false && $version == '') {
         $id = $this->hit($version);
         header('Location: ' . $download_as);
         exit;
     } else {
         if ($this->exists($hole, $version)) {
             // Calculate download as name
             $download_as = $this->download_as(true);
             // Record a hit
             $id = $this->hit($version);
             // Detect MIME type
             $mime = $this->mime_type($hole);
             // Send out the data
             header("Content-Type: {$mime}");
             header("Last-Modified: " . gmdate("D, d M Y H:i:s", mysql2date('U', $this->updated_at)) . " GMT");
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             // HTTP/1.1
             header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
             // Date in the past
             header("Content-Length: " . $this->filesize($hole, $version));
             if ($this->options['force_download'] == true) {
                 header('Content-Disposition: attachment; filename="' . basename($download_as) . '"');
             }
             header("Content-Transfer-Encoding: binary");
             if (!ini_get('safe_mode')) {
                 set_time_limit(0);
             }
             readfile($this->file($hole, $version));
             if ($id) {
                 DH_Access::finished($id, $this->filesize($hole, $version));
             }
             exit;
         }
     }
 }