showfiles.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. $dir = $_GET['dir'];
  3. $pwd = $dir;
  4. //These variables are to check whether the directory we will link to exists, and to know what directory we are in
  5. $check = @scandir($pwd.'/../', 1);
  6. $splode = preg_split('[/]', $pwd, -1);
  7. $predir = count($splode)-1;
  8. $test = array_slice($splode, -1, 1);
  9. #Establish MIME Type data
  10. #Link is used to specify special handler URLS for particular files
  11. #File specifies the link icon
  12. $arch_types = array(".tar",".gz",".z7",".bz",".bz2",".zip",".rar",".lsz",
  13. "link" => "",
  14. "file" => "tsarchive.gif");
  15. //Only MP3 supported for now
  16. $audio_types = array(".mp3",
  17. "link" => "index.php?nav=7&post=",
  18. "file" => "tsaudio.gif");
  19. $video_types = array(".ogv",
  20. "link" => "index.php?nav=8&post=",
  21. "file" => "tsmovie.gif");
  22. $image_types = array(".bmp",".gif",".jpg",".jpeg",".png",".ico",".svg",".xpm",
  23. "link" => "index.php?nav=9&post=",
  24. "file" => "tsimage.gif");
  25. $schematic_types = array(".dwg",".dxf",".cad",".gcode",".mcode",
  26. "link" => "",
  27. "file" => "tsschematic.gif");
  28. $model_types = array(".stl",".blend",".3ds",
  29. "link" => "",
  30. "file" => "tsmodel.gif");
  31. $binary_types = array(".exe",".o",".dll",".so",".jnilib",".a",".bin",".hex",
  32. "link" => "",
  33. "file" => "tssoftware.gif");
  34. $code_types = array(".py",".c",".h",".js",".php",".tcl",".m",".txt",
  35. "link" => "index.php?nav=6&post=",
  36. "file" => "tscode.gif");
  37. $doc_types = array(".htm",".html",".post",
  38. "link" => "index.php?nav=5&post=",
  39. "file" => "tsdoc.png");
  40. $legacy_types = array(".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".pages",".ai",".psd",".tiff",".tif",".eps",".ps",".xps",
  41. "link" => "index.php?nav=10&post=",
  42. "file" => "tsprop.png");
  43. $mime_types = array($arch_types,$audio_types,$video_types,$image_types,$schematic_types,$model_types,$binary_types,$code_types,$doc_types,$legacy_types);
  44. //Find the directory contents
  45. $ls = @scandir($pwd, 1);
  46. // $dlist = array_filter($ls,function ($a) {return is_dir($a);});
  47. $dban1 = '.';
  48. $dban2 = '..';
  49. $dkey = array_search($dban1,$ls);
  50. if ($dkey!==false){unset($ls[$dkey]);};
  51. $dkey = array_search($dban2,$ls);
  52. if ($dkey!==false){unset($ls[$dkey]);};
  53. //See if this directory is even there
  54. if (@in_array($test[0], $check)) {
  55. echo 'Directory listing for '.$pwd;
  56. echo '<hr />';
  57. $cnt = count($ls);
  58. $dlist = array();
  59. $flist = array();
  60. //Trying to sort here
  61. for ($n = 0; $n < $cnt; $n++) {
  62. $filechk = @scandir($pwd.'/'.$ls[$n]);
  63. if (! $filechk) {
  64. foreach($mime_types as $mimes) {
  65. foreach($mimes as $type) {
  66. $sstrn = @stristr($ls[$n],$type);
  67. if($sstrn !== FALSE && strlen($sstrn) == strlen($type)) {
  68. array_push($flist, $ls[$n]);
  69. }
  70. }
  71. }
  72. }
  73. else {
  74. array_push($dlist, $ls[$n]);
  75. }
  76. }
  77. sort($dlist);
  78. sort($flist);
  79. $ls = array_merge($dlist,$flist);
  80. //Yeah, I know this looks familiar. There's prolly some way to combine this by setting the $ikon and $link vars as an array.
  81. for ($n = 0; $n < $cnt; $n++) {
  82. //create links based on whether we are a file, and if otherwise we are a directory
  83. $filechk = @scandir($pwd.'/'.$ls[$n]);
  84. if (! $filechk) {
  85. //default values for uncaught filetypes
  86. $ikon = "tsfile.gif";
  87. $link = "";
  88. foreach ($mime_types as $mimes) {
  89. foreach ($mimes as $type) {
  90. //$link = $mimes["link"];
  91. $sstrn = @stristr($ls[$n],$type);
  92. if ($sstrn !== FALSE && strlen($sstrn) == strlen($type)) {
  93. $ikon = $mimes["file"];
  94. $link = $mimes["link"];
  95. break 2;
  96. };
  97. };
  98. };
  99. echo '<img class="icon" src='.$icondir.$ikon.' />';
  100. echo '<a href="'.$link.$pwd.'/'.$ls[$n].'">'.$ls[$n].'</a><br />';
  101. }
  102. else {
  103. echo '<img src="'.$icondir.'tsfolder.gif" />';
  104. echo '<a href="index.php?nav=1&dir='.$pwd.'/'.$ls[$n].'">'.$ls[$n].'</a><br />'."\n";
  105. }
  106. }
  107. //Figure out what the previous directory is
  108. $prevdirname = '';
  109. for ($i =0; $i < $predir; $i++) {
  110. //We want to catch the first case, and not put a / before it
  111. if ($i == 0) {
  112. $prevdirname = $prevdirname.$splode[$i];
  113. }
  114. else {
  115. $prevdirname = $prevdirname.'/'.$splode[$i];
  116. }
  117. }
  118. //If we are not in the TLD, make a link to the previous dir
  119. if ($prevdirname <> '') {
  120. echo '<img src="'.$icondir.'tsfolder-up.gif" />';
  121. echo '<a href="index.php?nav=1&dir='.$prevdirname.'">Up one level</a>'."\n";
  122. }
  123. }
  124. //Catch bogus directories
  125. else {
  126. include 'sys/fileshare/include/notfound';
  127. }
  128. ?>