Exemplo n.º 1
0
 /**
  * Set headers and send the file to the client
  *
  * @author Andreas Gohr <*****@*****.**>
  * @param string The full path to the file
  * @param string The Mime Type of the file
  */
 function sendFile($file, $mime, $overrideFileName = '')
 {
     // send headers
     header("Content-Type: {$mime}");
     list($start, $len) = VmConnector::http_rangeRequest(filesize($file));
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Accept-Ranges: bytes');
     //application mime type is downloadable
     if (strtolower(substr($mime, 0, 11)) == 'application') {
         if ($overrideFileName == '') {
             $filename = basename($file);
         } else {
             $filename = $overrideFileName;
         }
         header('Content-Disposition: attachment; filename="' . $filename . '";');
     }
     $chunksize = 1 * (1024 * 1024);
     // send file contents
     $fp = @fopen($file, "rb");
     if ($fp) {
         fseek($fp, $start);
         //seek to start of range
         $chunk = $len > $chunksize ? $chunksize : $len;
         while (!feof($fp) && $chunk > 0) {
             @set_time_limit();
             // large files can take a lot of time
             print fread($fp, $chunk);
             flush();
             $len -= $chunk;
             $chunk = $len > $chunksize ? $chunksize : $len;
         }
         fclose($fp);
     } else {
         header("HTTP/1.0 500 Internal Server Error");
         print "Could not read {$file} - bad permissions?";
         JFactory::getApplication()->close(true);
     }
 }