PageRenderTime 34ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/www/download.php

http://kandidat-cms.googlecode.com/
PHP | 84 lines | 77 code | 3 blank | 4 comment | 10 complexity | f0754109145ff04d28b9639d2f161c3f MD5 | raw file
Possible License(s): CC0-1.0
  1. <?php
  2. error_reporting(E_ALL^E_NOTICE);
  3. $path=str_replace('\\','/',dirname(__FILE__));
  4. include $path.'/code/functions.php';
  5. $directory=LOCALPATH.'/media/file';//??? ???? ??? ???????? ?????
  6. if(!$_GET['file']) die('Missing parameter!');
  7. if($_GET['file']{0}=='.') die('Wrong file!');
  8. @$fname =$_GET['file'];
  9. $fname = preg_replace('/..\//i','',$fname);
  10. $fullPath=$directory.'/'.$fname;
  11. if(file_exists($fullPath)){
  12. /* If the visitor is not a search engine, count the downoad: */
  13. if(!is_bot())
  14. inc_count($fname);
  15. if ($fd = fopen ($fullPath, "r")) {
  16. //????????? ????? ??????? ????
  17. $fsize = filesize($fullPath);
  18. $path_parts = pathinfo($fullPath);
  19. header("Content-type: application/octet-stream");
  20. header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
  21. header("Content-length: $fsize");
  22. header("Cache-control: private");
  23. //???????????? ??? ??????? ???????? ?????
  24. while(!feof($fd)) {
  25. $buffer = fread($fd, 2048);
  26. echo $buffer;
  27. }
  28. }
  29. fclose ($fd);
  30. exit;
  31. }else die("This file does not exist!");
  32. function is_bot(){
  33. /* This function will check whether the visitor is a search engine robot */
  34. $botlist = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
  35. "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
  36. "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
  37. "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
  38. "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
  39. "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
  40. "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
  41. "Butterfly","Twitturls","Me.dium","Twiceler");
  42. foreach($botlist as $bot){
  43. if(strpos($_SERVER['HTTP_USER_AGENT'],$bot)!==false)
  44. return true; // Is a bot
  45. }
  46. return false; // Not a bot
  47. }
  48. function inc_count($fname){
  49. $myFile=ENGINE.'logdb.php';
  50. @$count="";
  51. $present=0;
  52. if(is_readable($myFile)){
  53. $log=file($myFile);
  54. foreach ($log as $key => $val) {
  55. if (strpos($val,"$fname")!==FALSE) { $present = $key+1; break;}
  56. }
  57. if($present!=0){
  58. @$data=unserialize($log[$present-1]);
  59. @$count=$data['count'];
  60. }
  61. }
  62. $count++;
  63. $data=serialize(array("fname"=>"$fname",
  64. "count"=>$count))."\n";
  65. if($present!=0){
  66. $open=fopen($myFile,"w");
  67. for($i=0;$i<count($log);$i++){
  68. if($i!=($present-1)){fwrite($open,$log[$i]);
  69. }else{fwrite($open,$data);}
  70. }
  71. fclose($open);
  72. }else{
  73. $open=fopen($myFile,"a");
  74. fwrite($open, $data);
  75. fclose($open);
  76. }
  77. }
  78. ?>