Group-Office PHP Cross Reference Groupware Applications

Source: /modules/files/download.php - 145 lines - 3828 bytes - Summary - Text - Print

Description: Copyright Intermesh

   1  <?php
   2  /** 
   3   * Copyright Intermesh
   4   *
   5   * This file is part of Group-Office. You should have received a copy of the
   6   * Group-Office license along with Group-Office. See the file /LICENSE.TXT
   7   *
   8   * If you have questions write an e-mail to info@intermesh.nl
   9   *
  10   * @version $Id: download.php 7764 2011-07-28 09:45:30Z mschering $
  11   * @copyright Copyright Intermesh
  12   * @author Merijn Schering <mschering@intermesh.nl>
  13   */
  14  
  15  require_once ("../../Group-Office.php");
  16  
  17  require_once($GLOBALS['GO_MODULES']->modules['files']['class_path'].'files.class.inc.php');
  18  $files = new files();
  19  $fs = new filesystem();
  20  
  21  //close writing to session so other concurrent requests won't be locked out.
  22  session_write_close();
  23  
  24  
  25  if(!empty($_REQUEST['id']))
  26  {
  27      $file = $files->get_file($_REQUEST['id']);
  28      $path = $files->build_path($file['folder_id']).'/'.$file['name'];
  29  }else
  30  {
  31      $path = $_REQUEST['path'];
  32      $versioning = substr($path,0,10)=='versioning';
  33  
  34      if($versioning)
  35      {
  36          $path_parts = explode('/', $path);
  37          $file_id = $path_parts[1];
  38          $file = $files->get_file($file_id);
  39          $file['name']=utf8_basename($path);
  40      }else
  41      {       
  42          $file = $files->resolve_path($_REQUEST['path']);
  43      }
  44  }
  45  
  46  if(File::path_leads_to_parent($path))
  47      die('Invalid request');
  48  
  49  
  50  $public = substr($path,0,6)=='public';
  51  
  52  if($public && !$file)
  53  {
  54      $file=array('name'=>utf8_basename($path));
  55  }
  56  
  57  $path = $GLOBALS['GO_CONFIG']->file_storage_path.$path;
  58  
  59  $mode = isset($_REQUEST['mode'])  ? $_REQUEST['mode'] : 'download';
  60  
  61  if(!$file || !file_exists($path))
  62  {
  63      $GLOBALS['GO_LANGUAGE']->require_language_file('files');
  64      die($lang['files']['fileNotFound']);
  65  }
  66  
  67  /*
  68   * Enable browser caching for public files. They expire in one day.
  69   */
  70  
  71  
  72  /*
  73  //add timestamp for caching
  74  if(!isset($_REQUEST['mtime']))
  75  {
  76      header('Location: '.$_SERVER['PHP_SELF'].'?path='.urlencode($_REQUEST['path']).'&mode='.$mode.'&mtime='.filemtime($path));
  77      exit();
  78  }*/
  79  
  80  $random_code = isset($_REQUEST['random_code']) ? $_REQUEST['random_code'] : '';
  81  
  82  if ($public || $files->has_read_permission($GLOBALS['GO_SECURITY']->user_id, $file['folder_id']) || ($file['random_code']==$random_code && time()<$file['expire_time']))
  83  {
  84      /*
  85       * Remove new_filelink
  86       */
  87      if(!$public)
  88      {
  89          $files->delete_new_filelink($file['id'], $GLOBALS['GO_SECURITY']->user_id);
  90      }
  91  
  92      $browser = detect_browser();
  93  
  94      $extension = File::get_extension($file['name']);
  95  
  96      header('Content-Length: '.filesize($path));
  97      header('Content-Transfer-Encoding: binary');
  98  
  99      header("Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime($path))." GMT");
 100      header("ETag: ".md5_file($path));
 101  
 102  
 103      if($public)
 104      {
 105          header("Expires: " . date("D, j M Y G:i:s ", time()+86400) . 'GMT');//expires in 1 day
 106          header('Cache-Control: cache');
 107          header('Pragma: cache');
 108      }
 109  
 110      if ($browser['name'] == 'MSIE')
 111      {
 112          header('Content-Type: application/download');
 113          if($mode == 'download')
 114          {
 115              header('Content-Disposition: attachment; filename="'.$file['name'].'"');
 116          }else
 117          {
 118              header('Content-Disposition: inline; filename="'.$file['name'].'"');
 119          }
 120          if(!$public)
 121          {
 122              header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 123              header('Pragma: public');
 124          }
 125      }else
 126      {
 127          header('Content-Type: '.File::get_mime($path));
 128          if($mode == 'download')
 129          {
 130              header('Content-Disposition: attachment; filename="'.$file['name'].'"');
 131          }else
 132          {
 133              header('Content-Disposition: inline; filename="'.$file['name'].'"');
 134          }
 135          if(!$public)
 136          {
 137              header('Pragma: no-cache');
 138          }
 139      }
 140  
 141      readfile($path);
 142  }else
 143  {
 144      exit($lang['common']['accessDenied']);
 145  }

title

Description

title

Description

title

Description

title

title

Body