Your Ad Here

Posted By

michaJlS on 12/12/10


Tagged


Versions (?)

town watch


 / Published in: PHP
 

  1. <?php
  2. define('MEDIAWIKI',1);
  3. $preIP = dirname( __FILE__ );
  4. require_once( "$preIP/includes/WebStart.php" );
  5.  
  6.  
  7. $WhiteList = array(
  8. 'doc', 'docx', 'odt', 'rtf', 'psw', 'ott', 'docm', 'wps',
  9. 'ots', 'ods', 'xls', 'xlt', 'csv', 'pxl', 'xlm', 'xlsm', 'xlsx', 'xltx',
  10. 'odp', 'otp', 'ppt', 'pps', 'pptx', 'ppsx',
  11. 'pdf' , 'jpg' , 'jpeg' , 'jpg' , 'gif', 'bmp', 'png'
  12. );
  13.  
  14. if ( isset( $_COOKIE["{$wgCookiePrefix}UserID"] )
  15. && isset( $_COOKIE["{$wgCookiePrefix}UserName"])
  16. && isset($_SESSION['wsUserID'])
  17. && isset($_SESSION['wsToken'])
  18. && isset($_SESSION['wsUserName'])
  19. && $_COOKIE["{$wgCookiePrefix}UserID"] == $_SESSION['wsUserID']
  20. && $_COOKIE["{$wgCookiePrefix}UserName"] == $_SESSION['wsUserName']
  21.  
  22. ){
  23.  
  24. $requestedFile = realpath(dirname(__FILE__) . $_SERVER['REQUEST_URI']);
  25. $uploadDirectory = realpath($wgUploadDirectory);
  26. $fileInfo = pathinfo($requestedFile);
  27. $ext = mb_strtolower($fileInfo['extension']);
  28. if( file_exists($requestedFile) && ! is_dir($requestedFile) && is_file($requestedFile) ){
  29. if( $uploadDirectory == mb_substr($requestedFile,0,mb_strlen($uploadDirectory)) ){
  30. if( in_array($ext,$WhiteList) ){
  31. $mime = MimeMagic::singleton()->getTypesForExtension($ext);
  32. if( ! empty($mime) ){
  33. $mime = explode(' ',$mime);
  34. $mime = array_pop($mime);
  35. }
  36. if( empty($mime) ){
  37. header("Content-Disposition: attachment; filename=" . urlencode($fileInfo['basename']));
  38. header("Content-Type: application/force-download");
  39. header("Content-Type: application/octet-stream");
  40. header("Content-Type: application/download");
  41. }
  42. else{
  43. header("Content-Type: ".urlencode($mime));
  44. }
  45.  
  46. die(readfile($requestedFile));
  47. }
  48. }
  49. }
  50.  
  51.  
  52. }
  53.  
  54. die('Access denied. You must be logged in.');

Report this snippet  

You need to login to post a comment.