PageRenderTime 44ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 0ms

/ xvweb/file.php

http://xvweb.googlecode.com/
PHP | 182 lines | 155 code | 12 blank | 15 comment | 36 complexity | c1a84303ad6edf63ef709314568cf79d MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, LGPL-3.0
  1. <?php
  2. /***************************************************************************
  3. **************** Bordeux.NET Project *************************
  4. **************** File name : file.php *************************
  5. **************** Start : 22.05.2007 r. *************************
  6. **************** License : LGPL *************************
  7. **************** Version : 1.0 *************************
  8. **************** Authors : XVweb team *************************
  9. *************************XVweb Team*****************************************
  10. Krzyszof Bednarczyk, meybe you
  11. /////////////////////////////////////////////////////////////////////////////
  12. Klasa XVweb jest na licencji LGPL v3.0 ( GNU LESSER GENERAL PUBLIC LICENSE)
  13. ****************http://www.gnu.org/licenses/lgpl-3.0.txt********************
  14. Pe?na dokumentacja znajduje si? na stronie domowej projektu:
  15. *********************http://www.bordeux.NET/Xvweb***************************
  16. ***************************************************************************/
  17. header("Cache-Control: no-cache, must-revalidate");
  18. if(!isset($XVwebEngine)){
  19. header("location: http://".$_SERVER['HTTP_HOST']."/");
  20. exit;
  21. }
  22. include_once(ROOT_DIR.'config'.DIRECTORY_SEPARATOR.'files.config.php');
  23. $TMPFileDir = dirname(__FILE__).DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR;
  24. $XVwebEngine->FilesClass()->Date['FilesDir'] = $UploadDir;
  25. $IDFile = $XVwebEngine->GetFromURL($PathInfo, 2);
  26. if(!empty($IDFile)){
  27. if(!is_numeric($IDFile)){
  28. header("location: ".$URLS['Script'].'System/BadIDFile/');
  29. exit;
  30. }
  31. if(isset($_GET['Delete']) && $_GET['SIDCheck'] == $GLOBALS['XVwebEngine']->Session->GetSID()){
  32. try {
  33. $XVwebEngine->FilesClass()->DeleteFile($IDFile);
  34. } catch (XVwebException $e) {
  35. if($e->getCode() == 1)
  36. header("location: ".$URLS['Script'].'System/AccessDenied/'); else
  37. header("location: ".$URLS['Script'].'System/Error/');
  38. exit;
  39. }
  40. header("location: ".$URLS['Script'].'System/FileDeleted/');
  41. exit;
  42. }
  43. function DetectType(){
  44. global $FileInfo, $ctype, $IsImage, $viewFileHeader;
  45. switch ($FileInfo['Extension']) {
  46. case "pdf": $ctype="application/pdf"; break;
  47. case "exe": $ctype="application/octet-stream"; break;
  48. case "zip": $ctype="application/zip"; break;
  49. case "doc": $ctype="application/msword"; break;
  50. case "xls": $ctype="application/vnd.ms-excel"; break;
  51. case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
  52. case "gif": $ctype="image/gif"; $IsImage= true; $viewFileHeader= ""; break;
  53. case "png": $ctype="image/png"; $IsImage= true; $viewFileHeader= ""; break;
  54. case "bmp": $ctype="image/bmp"; $IsImage= true; $viewFileHeader= ""; break;
  55. case "jpeg":$ctype="image/jpg"; $IsImage= true; $viewFileHeader= ""; break;
  56. case "jpg": $ctype="image/jpg"; $IsImage= true; $viewFileHeader= "";break;
  57. case "swf": $ctype="application/x-shockwave-flash"; $IsImage= true; $viewFileHeader= "";break;
  58. default: $ctype="application/force-download";
  59. }
  60. }
  61. if(($XVwebEngine->GetFromURL($PathInfo, 3))){
  62. if(!xvPerm("DownloadFile")){
  63. header("location: ".$URLS['Script'].'System/AccessDenied/?flag=DownloadFile');
  64. exit;
  65. }
  66. $FileInfo = $XVwebEngine->FilesClass()->GetFile($IDFile, true);
  67. if($XVwebEngine->Plugins()->Menager()->event("onPreDownload")) eval($XVwebEngine->Plugins()->Menager()->event("onPreDownload"));
  68. $viewFileHeader=" attachment;";
  69. $IsImage = false;
  70. if(isset($_GET['Download'])) $ctype="application/force-download"; else{
  71. DetectType();
  72. }
  73. $NameClassFile = 'XV_Files_'.$FileInfo['Server'];
  74. if(!class_exists($NameClassFile)){
  75. exit("Server not found: ".$FileInfo['Server']. ' . Please add in config.php '.$NameClassFile.' class');
  76. }
  77. $ClassFile = new $NameClassFile;
  78. $FileLocation = $ClassFile->download($FileInfo['MD5File'].$FileInfo['SHA1File']);
  79. @set_time_limit(0);
  80. if($viewFileHeader=="" && $IsImage && ((isset($_GET['width']) && is_numeric($_GET['width'])) or (isset($_GET['height']) && is_numeric($_GET['height'])))){
  81. $Old = $FileLocation;
  82. $FileLocation = Cache_dir.$FileInfo['MD5File'].$FileInfo['SHA1File'].(isset($_GET['width']) ? $_GET['width'] :"").'x'.(isset($_GET['height']) ? $_GET['height'] :"").'.'.$FileInfo['Extension'];
  83. if(!file_exists($FileLocation)){
  84. include_once($LocationXVWeb.DIRECTORY_SEPARATOR.'libraries'.DIRECTORY_SEPARATOR.'ResizeImage.class.php');
  85. $image = new SimpleImage();
  86. $image->load($Old);
  87. if(isset($_GET['height']))
  88. $image->resizeToHeight($_GET['height']);
  89. if(isset($_GET['width']))
  90. $image->resizeToWidth($_GET['width']);
  91. $image->save($FileLocation);
  92. }
  93. }
  94. if($ctype == "application/zip"){
  95. $Zip = $XVwebEngine->GetFromURL($PathInfo, 4);
  96. if(!empty($Zip)){
  97. $FileInZip = substr($PathInfo, strlen('/File/'.$XVwebEngine->GetFromURL($PathInfo, 2).'/'.$XVwebEngine->GetFromURL($PathInfo, 3).'/'), -1);
  98. $ZipFileLoc = $FileLocation;
  99. $FileInfo['MD5File'] = md5(('zip://' .$FileLocation. '#'.$FileInZip));
  100. $FileLocation = (Cache_dir.$FileInfo['MD5File']);
  101. if(!file_exists($FileLocation)){
  102. if(!@file_put_contents($FileLocation , file_get_contents('zip://' .$ZipFileLoc. '#'.$FileInZip))){
  103. header("location: ".$URLS['Script'].'System/BadIDFile/');
  104. exit;
  105. }
  106. }
  107. $FileInfo['Extension'] = pathinfo($FileInZip, PATHINFO_EXTENSION);
  108. $FileInfo['FileName'] = pathinfo($FileInZip, PATHINFO_FILENAME );
  109. DetectType();
  110. }
  111. }
  112. ob_clean();
  113. header("Pragma: public");
  114. header("Expires: Sat, 26 Jul 2012 05:00:00 GMT");
  115. header("Etag: ".$FileInfo['MD5File']);
  116. header("Cache-Control: maxage=50000, post-check=0, pre-check=0");
  117. header("Cache-Control: private",false);
  118. header("Content-Type: ".$ctype);
  119. header("Content-Disposition:".$viewFileHeader." filename=\"".$FileInfo['FileName'].'.'.$FileInfo['Extension']."\";");
  120. header("Content-Transfer-Encoding: binary");
  121. header("Content-Length: ".filesize($FileLocation));
  122. $DownloadRate = $XVwebEngine->Config("config")->find('config downloadlimit')->text();
  123. if(!empty($DownloadRate) && $DownloadRate != 0){
  124. flush();
  125. $file = fopen($FileLocation , "r");
  126. while(!feof($file)) {
  127. print fread($file, round($DownloadRate * 1024));
  128. flush();
  129. sleep(1);
  130. }
  131. fclose($file);
  132. }else {
  133. @readfile($FileLocation ) or die($Language['Error']);
  134. }
  135. exit;
  136. }
  137. $FileInfo = $XVwebEngine->FilesClass()->GetFile($IDFile);
  138. if(is_null($FileInfo["ID"])){
  139. header("location: ".$URLS['Script'].'System/BadIDFile/');
  140. exit;
  141. }
  142. $FileInfo['FileSize'] = $XVwebEngine->FilesClass()->size_comp($FileInfo['FileSize']);
  143. $Smarty->assign('File', $FileInfo);
  144. $Smarty->assign('FileInfo', true);
  145. $Smarty->assign('IntervalTime', sprintf($Language['IntervalTime'], ($XVwebEngine->FilesClass()->Date['CacheTime'] / 60) ));
  146. $Smarty->display('file_show.tpl');
  147. exit;
  148. }
  149. if(isset($_GET['SendFile']) && is_array($_FILES['UploadForm'])){
  150. if(!(xvPerm('AddFile'))){
  151. header("location: ".$URLS['Script'].'System/AccessDenied/');
  152. exit;
  153. }
  154. $SaveFiles = array();
  155. foreach ($_FILES['UploadForm']['tmp_name'] as $Key=>$TMPLocation){
  156. $strUploadDir = $TMPFileDir . $_FILES['UploadForm']['name'][$Key];
  157. if(move_uploaded_file($TMPLocation, $strUploadDir ) )
  158. $SaveFiles[] = $XVwebEngine->FilesClass()->AddFile($strUploadDir); else
  159. $SaveFiles[] = array("Result"=>"Failed");
  160. if($XVwebEngine->Plugins()->Menager()->event("onUploadFile")) eval($XVwebEngine->Plugins()->Menager()->event("onUploadFile"));
  161. }
  162. unset($TMPLocation);
  163. $Smarty->assign('ViewCode', true);
  164. $Smarty->assign('FileList', $SaveFiles);
  165. $Smarty->display('file_show.tpl');
  166. exit;
  167. }
  168. $Smarty->assign('UploadForm', true);
  169. $Smarty->display('file_show.tpl');
  170. ?>