PageRenderTime 56ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/filelist.php

https://github.com/exedre/e4t-emacs
PHP | 1212 lines | 864 code | 179 blank | 169 comment | 494 complexity | 47cbcdaf28698956aba69c6d3c299e8e MD5 | raw file
Possible License(s): GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?PHP
  2. error_reporting(0); // this needs to be set to 0 when releases are released
  3. /**
  4. * File: filelist.php
  5. *
  6. * Bobb's File List System
  7. */
  8. $version = '3.2.0';
  9. /*
  10. * Read the README file. It is a must read for all admins and
  11. * programmers that use or intend to edit this program. If you read nothing else
  12. * in that file, read "Notes about security" near the bottom.
  13. *
  14. * Bobb's File Manage System is the legal property of its developers whose names are listed in the COPYRIGHT file.
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. */
  30. // SETINGS:
  31. /******************************************************/
  32. // GENERAL FILELIST SETTINGS
  33. $display_new = true; // display "new" when they are new files/dirs
  34. $display_updated = true; // display "updated" when they are updated files/dirs
  35. $new_time_secs = 60 * 60 * 24 * 14; // "new" and "updated" deadline, 14 days
  36. $error_spacer = 0.5; // for per word errors; exact match 0~~.5~~1 accept all (see below for further info); used in function isclosematch()
  37. $error_spacer2 = 0.3; // for per segment errors; exact match 0~~.5~~1 accept all (see below for further info); used in function isclosematch()
  38. $show_all_stats = false; // show or don't show the "totals" stats at the bottom of the page
  39. $organize_ord = false; // when organizing, organize ignoring leading 'the's or 'a's?
  40. $show_add_info = false; // some files such as images, text, music, and video files will have more information that can be displayed about it (music and video files require getid3() (www.sourceforge.net/projects/getid3/)
  41. $line_break = "\n"; // line break for creating files; "\n" is general line break, but some Windows apps like "\n\r" better
  42. $auto_icon = false; // this feature allows an admin to edit the acceptable file extensions without having to change the linked icon images. So unless custom icons or obscure extensions (that icons should be linked to) are being used, this remaining true is most likely a good thing
  43. /*
  44. * ERROR_SPACER explaination
  45. *
  46. * 0 will only return exact matches. 1 will return everything (you don't want
  47. * that!) I suggest somewhere inbetween. 0.5 allows about half the characters to
  48. * be changed, and still return true. I use this on per word matches, since it
  49. * will allow for more spelling erros in a word. 0.3 allows a little less than a
  50. * third of the characters to be wrong. Per segment matches are more strict
  51. * since they aren't as clean cut, and will also include spaces and other odd
  52. * characters that normally may not be considered.
  53. *
  54. */
  55. if(isset($_GET['prop']) || isset($_GET['note']))
  56. $dontdispheader = true;
  57. else
  58. $dontdispheader = false;
  59. // If $auto_icon is enabled, you can ignore the $iconlink array.
  60. // these two keys will match together to display
  61. // the right icons with the filetype
  62. $accept = array(
  63. // acceptible file endings. for best result include the '.' in a desired file extension
  64. // if you add '' to the list, it will display all files.
  65. '.pdf',
  66. '.xls',
  67. );
  68. // ignore this if $auto_icon is enabled
  69. if(!$auto_icon || !$dontdispheader){
  70. $iconlink = array(
  71. // linked to src of image you want
  72. '/icons/compressed.gif',
  73. '/icons/compressed.gif',
  74. '/icons/compressed.gif',
  75. '/icons/compressed.gif',
  76. '/icons/burst.gif',
  77. '/icons/comp.gray.gif',
  78. '/icons/layout.gif',
  79. '/icons/layout.gif',
  80. '/icons/layout.gif',
  81. '/icons/image2.gif',
  82. '/icons/image2.gif',
  83. '/icons/image2.gif',
  84. '/icons/image2.gif',
  85. '/icons/movie.gif',
  86. '/icons/movie.gif',
  87. '/icons/movie.gif',
  88. '/icons/movie.gif',
  89. '/icons/movie.gif',
  90. '/icons/movie.gif',
  91. '/icons/sound2.gif',
  92. '/icons/sound2.gif',
  93. '/icons/sound2.gif',
  94. '/icons/sound1.gif',
  95. '/icons/image1.gif',
  96. '/icons/text.gif',
  97. '/icons/text.gif',
  98. '/icons/unknown.gif'
  99. );
  100. }
  101. /******************************************************/
  102. // $loc1 is the path on the computer filelist's location
  103. $loc1 = dirname(__FILE__);
  104. // makes a standardized variable for $PHP_SELF, which is in two places depending on the PHP version
  105. if(isSet($PHP_SELF))
  106. $phpSelf = $PHP_SELF;
  107. else
  108. $phpSelf = $_SERVER['PHP_SELF'];
  109. if(!is_dir('filelist/'))
  110. mkdir('filelist/') or die('Not enough permissions to create directory');
  111. hits(); // log hits/page views
  112. // assigns $php_version to an array, representing the version and sub versions
  113. $php_version = explode('.', phpversion());
  114. if($php_version[0] > 4 || ($php_version[0] == 4 && $php_version[1] >= 2)){
  115. if(!$dontdispheader){
  116. $logFile = 'filelist/last_update.list';
  117. if($show_all_stats && is_file($logFile)){
  118. $array_of_log_file = file($logFile);
  119. $number_of_dirs = trim($array_of_log_file[1]);
  120. $number_of_files = trim($array_of_log_file[2]);
  121. $number_of_all = trim($array_of_log_file[1]) + trim($array_of_log_file[2]);
  122. $total_file_size = trim($array_of_log_file[3]);
  123. $last_update = trim($array_of_log_file[0]);
  124. } else
  125. $number_of_all = 10000;
  126. // max amount of time to wait before updating (with $noa ^ 2 / 5000, this will be about 5.6 hours)
  127. if($number_of_all > 10000)
  128. $number_of_all = 10000;
  129. $update_log_sec = round($number_of_all * $number_of_all / 5000); // how frequently to update number of files/filesize log
  130. }
  131. // $cur_filename is the name of the index file, so it can be named anything, and still work correctly
  132. $cur_filename = '.php';
  133. if(strstr($phpSelf, '/')){
  134. $i = strlen($phpSelf);
  135. while($i > 0 && $cur_filename == '.php'){
  136. $i--;
  137. if(substr($phpSelf, $i, 1) == '/')
  138. $cur_filename = substr($phpSelf, $i + 1, strlen($phpSelf));
  139. }
  140. }
  141. // $cur_dir is the directory path from the web server
  142. $cur_dir = stripslashes(str_replace("/$cur_filename", '', $phpSelf));
  143. // $loc is the location (in filelist) to view files in $loc directory
  144. if(!isset($_GET['loc']) || @$_GET['loc'] == '/' || @strstr($_GET['loc'], '..') || @strstr(strtolower($_GET['loc']), 'filelist'))
  145. $loc = '.';
  146. else
  147. $loc = $_GET['loc'];
  148. // the next three tests make sure $loc is standardized to easier use
  149. if(substr($loc, 0, 1) == '.')
  150. $loc = substr($loc, 1);
  151. if(substr($loc, 0, 1) != '/')
  152. $loc = '/' . $loc;
  153. if(substr($loc, -1) != '/')
  154. $loc = $loc . '/';
  155. // get arangment type from the URL, if it doesn't exist, set to default
  156. if(isset($_GET['arange']))
  157. $arange = $_GET['arange'];
  158. else
  159. $arange = 'na';
  160. // split $arange into its two components
  161. $ar1 = substr($arange, 0, 1);
  162. if($ar1 != 'n' && $ar1 != 't' && $ar1 != 's')
  163. $ar1 = 'n';
  164. $ar2 = substr($arange, 1, 1);
  165. if($ar2 != 'a' && $ar2 != 'd')
  166. $ar2 = 'a';
  167. if($auto_icon && !$dontdispheader){
  168. $autoicon_ud = false;
  169. if(is_file('filelist/autoicon.list')){
  170. $autoicon_file = file('filelist/autoicon.list');
  171. if(trim($autoicon_file[0]) <= filemtime($loc1 . '/' . $cur_filename))
  172. $autoicon_ud = true;
  173. else
  174. for($i = 1; $i < count($autoicon_file); $i++)
  175. $iconlink[$i - 1] = trim($autoicon_file[$i]);
  176. } else
  177. $autoicon_ud = true;
  178. if($autoicon_ud){
  179. if(in_array('',$accept)){
  180. if($accept[count($accept) - 1] != ''){
  181. $blkloc = array_search('', $accept);
  182. //unset($accept[$blkloc]);
  183. for($i = $blkloc; $i < count($accept); $i++)
  184. $accept[$i] = $accept[$i + 1];
  185. $accept[count($accept) - 1] = '';
  186. }
  187. }
  188. $lst1 = array(
  189. '.zip','.tar.gz','.7z','.rar','.exe','.msi','.html','.htm','.php','.php3',
  190. '.php4','.php5','.phtml','.jpg','.jpeg','.gif','.tiff','.tif','.png','.avi',
  191. '.asf','.mpg','.mpeg','.wmv','.mov','.mp3','.wma','.wav','.psd','.txt',
  192. '.list','.bin','.dvi','.iso','.pdf','.js','.vbs','.tar',''
  193. );
  194. $lst2 = array(
  195. '/icons/compressed.gif','/icons/compressed.gif','/icons/compressed.gif',
  196. '/icons/compressed.gif','/icons/burst.gif','/icons/comp.gray.gif',
  197. '/icons/layout.gif','/icons/layout.gif','/icons/layout.gif',
  198. '/icons/layout.gif','/icons/layout.gif','/icons/layout.gif',
  199. '/icons/layout.gif','/icons/image2.gif','/icons/image2.gif',
  200. '/icons/image2.gif','/icons/image2.gif','/icons/image2.gif',
  201. '/icons/image2.gif','/icons/movie.gif','/icons/movie.gif',
  202. '/icons/movie.gif','/icons/movie.gif','/icons/movie.gif',
  203. '/icons/movie.gif','/icons/sound2.gif','/icons/sound2.gif',
  204. '/icons/sound1.gif','/icons/image1.gif','/icons/text.gif',
  205. '/icons/text.gif','/icons/binary.gif','/icons/dvi.gif',
  206. '/icons/diskimg.gif','/icons/pdf.gif','/icons/script.gif',
  207. '/icons/script.gif','/icons/tar.gif','/icons/unknown.gif'
  208. );
  209. foreach($lst1 as $i => $val){
  210. if(in_array($val, $accept)){
  211. $aryky = array_search($val, $accept);
  212. $iconlink[$aryky] = $lst2[$i];
  213. }
  214. }
  215. $write = implode($line_break, $iconlink);
  216. $fout = fopen($loc1 . '/filelist/autoicon.list', 'w');
  217. $fp = fwrite($fout, time() . $line_break . $write);
  218. fclose($fout);
  219. }
  220. }
  221. // if the array is setup to accept all extensions set vairable
  222. if(in_array('', $accept))
  223. $accept_all = true;
  224. else
  225. $accept_all = false;
  226. // if additional information can be displayed about the files, test for getid3
  227. if($show_add_info)
  228. if(@include_once('getid3/getid3/getid3.php')){
  229. $getid3_true = 1; $getid3_true2 = 1;
  230. } else {
  231. $getid3_true = 0; $getid3_true2 = 0;
  232. }
  233. else {
  234. $getid3_true = 0;
  235. if(@include_once('getid3/getid3/getid3.php'))
  236. $getid3_true2 = 1;
  237. else
  238. $getid3_true2 = 0;
  239. }
  240. // set default of $parent_loc to the root directory
  241. $parent_loc = $phpSelf . '?loc=.';
  242. // set $parent_loc to actual location parent directory
  243. $array_of_path = explode('/', substr($loc, 0, -1));
  244. for($i = 1; $i < count($array_of_path) - 1; $i++)
  245. $parent_loc .= '/' . $array_of_path[$i];
  246. // get directory names aranged into $sup_dirs to display in title and the top of the page
  247. $dir_left = '.' . substr($loc, 0, -1);
  248. $sup_dirs[0] = $dir_left;
  249. while(substr($dir_left, 1) != ''){
  250. $array_of_path = explode('/', $dir_left);
  251. $lnk_num = count($sup_dirs);
  252. $sup_dirs[$lnk_num] = '.';
  253. for($i = 1; $i < count($array_of_path) - 1; $i++)
  254. $sup_dirs[$lnk_num] .= '/' . $array_of_path[$i];
  255. $dir_left = $sup_dirs[$lnk_num];
  256. }
  257. if(isset($_GET['search_value']) && $_GET['search_value'] != '' && $_GET['search_value'] != 'Search'){
  258. $search_value = $_GET['search_value'];
  259. $count = 0;
  260. // not \ / ; * ? " < > | #
  261. // characters 32-126 !34 !35 !42 !47 !59 !60 !62 !63 !92 !124
  262. for($i = 32; $i <= 126; $i++)
  263. if($i != 34 && $i != 35 && $i != 42 && $i != 47 && $i != 59
  264. && $i != 60 && $i != 62 && $i != 63 && $i != 92 && $i != 124){
  265. $chr_array[$count] = chr($i);
  266. $count++;
  267. }
  268. for($i = 0; $i < strlen($search_value); $i++){
  269. $char = substr($search_value, $i, 1);
  270. $chr_done = false;
  271. for($j = 0; $j < count($chr_array) && !$chr_done; $j++){
  272. if($chr_array[$j] == $char)
  273. $chr_done = true;
  274. }
  275. if(!$chr_done){
  276. echo '<font color="red">Search contains invalid character, "'. $char .'"</font><br>';
  277. $search_value = 'Search';
  278. }
  279. }
  280. } else
  281. $search_value = 'Search';
  282. if(isset($_GET['showsearch']) && $_GET['showsearch'] != '')
  283. $showsearch = $_GET['showsearch'];
  284. else
  285. $showsearch = 0;
  286. if(isset($_GET['exactmatch']) && $_GET['exactmatch'] != '')
  287. $exactmatch = $_GET['exactmatch'];
  288. else
  289. $exactmatch = 0;
  290. $adlnk = '';
  291. $adlnk2 = '';
  292. if($search_value != 'Search'){
  293. $adlnk2 .= '&search_value=' . $search_value;
  294. if(isset($showsearch))
  295. $adlnk2 .= '&showsearch=' . $showsearch;
  296. if(isset($exactmatch))
  297. $adlnk2 .= '&exactmatch=' . $exactmatch;
  298. }
  299. echo '<html><head>';
  300. echo '<STYLE type=text/css><!--';
  301. echo 'A:link{color:#FFFFFF}';
  302. echo 'A:visited{color:#FFFFFF}';
  303. echo 'A:active{color:#F0F0F0}';
  304. echo 'A:hover{color:#E0E0E0;text-decoration:none}';
  305. echo '--></STYLE><title>Files in gialla';
  306. // display the path of where filelist is currently pointing
  307. $array_of_path = explode('/', substr($loc, 0, -1));
  308. for($i = 1, $j = count($sup_dirs) - 2; $i < count($array_of_path); $i++, $j--)
  309. echo ' < ' . $array_of_path[$i];
  310. echo '</title>';
  311. echo "</head><body bgcolor=\"#000000\" text=\"#FFFFFF\" vlink=\"#FFFFFF\" alink=\"#FFFFFF\" link=\"#FFFFFF\">";
  312. if(!$dontdispheader){
  313. echo '<table width="100%" cellpadding="2" cellspacing="0" border="0"><tr><td>';
  314. echo '<font size="+2"><b>Files in ';
  315. echo "<a href=\"$phpSelf?loc=.$adlnk\">root</a>\n";
  316. // display the path of where filelist is currently pointing
  317. for($i = 1, $j = count($sup_dirs) - 2; $i < count($array_of_path); $i++, $j--)
  318. echo ' < ' . "<a href=\"$phpSelf?loc=$sup_dirs[$j]$adlnk\">$array_of_path[$i]</a>\n";
  319. echo '</b></font>';
  320. echo '</td></tr></table><br>';
  321. }
  322. // if the associated variable is found in the URL and the user has permissions to do such thing then continue
  323. // if a note is going to be displayed
  324. if(isset($_GET['note'])){
  325. $note = $_GET['note'];
  326. //<a href="" onClick="JavaScript:window.open(\''.$phpSelf.'?note=1\',\'note\',\'width=200,height=200,dependent=yes,location=no,scrollbars=yes,menubar=no,status=no,resizable=yes\')">(?)</a>
  327. switch($note){
  328. case 2:
  329. echo 'The file path is determined by the path from the File Manage file. This does not include any additional path that the server may have, nor does it include the webserver\'s path.';
  330. break;
  331. case 3:
  332. echo 'Audio/Video information is gathered from the open source program <a href="http://www.sourceforge.net/projects/getid3/">getid3()</a>. ';
  333. break;
  334. case 5:
  335. echo 'A search locates files and folders in the current directory with exact and similar matches (unless "Exact results only" is selected). Currently similar matches can be '. ($error_spacer * 100) .'% incorrect on a per word basis, and '. ($error_spacer2 * 100) .'% incorrect on a per phrase basis. Per phrase will include spaces and other chance word anomalies that would make it more likely to match, so it should be a lower value.';
  336. break;
  337. default:
  338. echo 'No note for this';
  339. }
  340. echo '<br><input type="button" onClick="JavaScript=window.close()" value="Close Window">';
  341. } else
  342. // displays properties of a file
  343. if(isset($_GET['prop']) && $_GET['prop'] != '' && is_file($loc1 . $_GET['prop']) && allowed($_GET['prop'], true, false, true)){
  344. $prop = $_GET['prop'];
  345. // if getid3 is going to be called, set up $filename, then get info
  346. if($getid3_true2){
  347. $filename = $loc1 . $prop;
  348. $getID3 = new getID3;
  349. $fileinfo = $getID3->analyze($filename);
  350. }
  351. echo '<div align="center"><font size="+1"><b>File Properties</b></font></div><br>';
  352. echo '<table cellpadding="4" cellspacing="0" border="1" align="center">';
  353. echo '<tr><td align="right">File name</td><td><a title="Open file in separate window" target="_blank" href="' .$cur_dir . $prop .'">'. get_name($prop) .'</a></td></tr>';
  354. echo '<tr><td align="right"><a href="" onClick="JavaScript:window.open(\''.$phpSelf.'?note=2\',\'note\',\'width=200,height=200,dependent=yes,location=no,scrollbars=yes,menubar=no,status=no,resizable=yes\')">(?)</a> File path</td><td>'. $prop .'</td></tr>';
  355. $file_size = filesize($loc1 . $prop);
  356. echo '<tr><td align="right">File size</td><td>';
  357. if($file_size > 980)
  358. echo filesz($file_size) . ', ';
  359. echo $file_size .' bytes</td></tr>';
  360. echo '<tr><td align="right">File created</td><td>'. date("F d, Y H:i (O)", filectime($loc1 . $prop)) .'</td></tr>';
  361. echo '<tr><td align="right">File modified</td><td>'. date("F d, Y H:i (O)", filemtime($loc1 . $prop)) .'</td></tr>';
  362. echo '<tr><td align="right">File accessed</td><td>'. date("F d, Y H:i (O)", fileatime($loc1 . $prop)) .'</td></tr>';
  363. @$image_info = getimagesize($loc1 . $prop);
  364. if(isset($image_info[2])){
  365. $image_type_array = array(NULL,'GIF','JPG','PNG','SWF','PSD','BMP','TIFF(intel byte order)',
  366. 'TIFF(motorola byte order)','JPC','JP2','JPX','JB2','SWC','IFF','WBMP','XBM');
  367. $image_channel_array = array(NULL,' (gray scale)',NULL,' (RGB)',' (CMYK)');
  368. echo '<tr><td align="right">Image info:</td><td>';
  369. echo 'Image resolution: '. $image_info[0] .'x'. $image_info[1] .'<br>';
  370. echo 'Image type: '. $image_type_array[$image_info[2]] .'<br>';
  371. if(isset($image_info['bits']))
  372. echo 'Image depth: '. $image_info['bits'] .'-bit<br>';
  373. if(isset($image_info['channels']))
  374. echo 'Image channels: '. $image_info['channels'] . $image_channel_array[$image_info['channels']] .'<br>';
  375. echo '</td></tr>';
  376. } else
  377. // get a heck of a lot of ID3 info here, dang!
  378. if($getid3_true2 && isset($fileinfo['fileformat'])){
  379. echo '<tr><td align="right"><a href="" onClick="JavaScript:window.open(\''.$phpSelf.'?note=3\',\'note\',\'width=175,height=150,dependent=yes,location=no,scrollbars=yes,menubar=no,status=no,resizable=yes\')">(?)</a> Audio/Video Info</td><td>';
  380. echo 'Format: '. $fileinfo['fileformat'] .'<br>';
  381. echo 'Length: '. $fileinfo['playtime_string'] .'<br>';
  382. echo 'Bitrate: '. round($fileinfo['bitrate'] / 1000) .' kbps<br>';
  383. if(isset($fileinfo['video']['codec']))
  384. echo 'Video codec: '. $fileinfo['video']['codec'] .'<br>';
  385. echo 'Audio channels: '. $fileinfo['audio']['channels'] .'<br>';
  386. echo 'Audio sample rate: '. $fileinfo['audio']['sample_rate'] .' Hz<br>';
  387. if(isset($fileinfo['audio']['bits_per_sample']))
  388. echo 'Audio sample size: '. $fileinfo['audio']['bits_per_sample'] .' bits<br>';
  389. if(isset($fileinfo['tags']['id3v1']) || isset($fileinfo['tags']['id3v1'])){
  390. if(isset($fileinfo['tags']['id3v1']['title'][0]))
  391. echo 'Song title: '. $fileinfo['tags']['id3v1']['title'][0] .'<br>';
  392. if(isset($fileinfo['tags']['id3v1']['artist'][0]))
  393. echo 'Song artist: '. $fileinfo['tags']['id3v1']['artist'][0] .'<br>';
  394. if(isset($fileinfo['tags']['id3v1']['album'][0]))
  395. echo 'Song album: '. $fileinfo['tags']['id3v1']['album'][0] .'<br>';
  396. if(isset($fileinfo['tags']['id3v2']['genre'][0]))
  397. echo 'Song genre: '. $fileinfo['tags']['id3v2']['genre'][0] .'<br>';
  398. elseif(isset($fileinfo['tags']['id3v1']['genre'][0]))
  399. echo 'Song genre: '. $fileinfo['tags']['id3v1']['genre'][0] .'<br>';
  400. if(isset($fileinfo['tags']['id3v1']['track'][0]))
  401. echo 'Song track: '. $fileinfo['tags']['id3v1']['track'][0] .'<br>';
  402. if(isset($fileinfo['tags']['id3v1']['year'][0]))
  403. echo 'Song year: '. $fileinfo['tags']['id3v1']['year'][0] .'<br>';
  404. if(isset($fileinfo['tags']['id3v2']['composer'][0]))
  405. echo 'Song composer: '. $fileinfo['tags']['id3v2']['composer'][0] .'<br>';
  406. if(isset($fileinfo['tags']['id3v2']['publisher'][0]))
  407. echo 'Song publisher: '. $fileinfo['tags']['id3v2']['publisher'][0] .'<br>';
  408. } else
  409. if(isset($fileinfo['tags'][$fileinfo['fileformat']])){
  410. if(isset($fileinfo['tags'][$fileinfo['fileformat']]['title'][0]))
  411. echo 'Song title: '. $fileinfo['tags'][$fileinfo['fileformat']]['title'][0] .'<br>';
  412. if(isset($fileinfo['tags'][$fileinfo['fileformat']]['artist'][0]))
  413. echo 'Song artist: '. $fileinfo['tags'][$fileinfo['fileformat']]['artist'][0] .'<br>';
  414. if(isset($fileinfo['tags'][$fileinfo['fileformat']]['album'][0]))
  415. echo 'Song album: '. $fileinfo['tags'][$fileinfo['fileformat']]['album'][0] .'<br>';
  416. if(isset($fileinfo['tags'][$fileinfo['fileformat']]['genre'][0]))
  417. echo 'Song genre: '. $fileinfo['tags'][$fileinfo['fileformat']]['genre'][0] .'<br>';
  418. elseif(isset($fileinfo['tags'][$fileinfo['fileformat']]['genre'][0]))
  419. echo 'Song genre: '. $fileinfo['tags'][$fileinfo['fileformat']]['genre'][0] .'<br>';
  420. if(isset($fileinfo['tags'][$fileinfo['fileformat']]['track'][0]))
  421. echo 'Song track: '. $fileinfo['tags'][$fileinfo['fileformat']]['track'][0] .'<br>';
  422. if(isset($fileinfo['tags'][$fileinfo['fileformat']]['year'][0]))
  423. echo 'Song year: '. $fileinfo['tags'][$fileinfo['fileformat']]['year'][0] .'<br>';
  424. if(isset($fileinfo['tags'][$fileinfo['fileformat']]['composer'][0]))
  425. echo 'Song composer: '. $fileinfo['tags'][$fileinfo['fileformat']]['composer'][0] .'<br>';
  426. if(isset($fileinfo['tags'][$fileinfo['fileformat']]['publisher'][0]))
  427. echo 'Song publisher: '. $fileinfo['tags'][$fileinfo['fileformat']]['publisher'][0] .'<br>';
  428. }
  429. if(isset($fileinfo['video']['resolution_x']))
  430. echo 'Video resolution: '. $fileinfo['video']['resolution_x'] . 'x' . $fileinfo['video']['resolution_y'] .'<br>';
  431. if(isset($fileinfo['video']['frame_rate']))
  432. echo 'Video frame rate: '. $fileinfo['video']['frame_rate'] .'<br>';
  433. if(isset($fileinfo['video']['bits_per_sample']))
  434. echo 'Video sample size: '. $fileinfo['video']['bits_per_sample'] .' bits<br>';
  435. if(isset($fileinfo[$fileinfo['fileformat']]['video']['color_depth']))
  436. echo 'Video color depth: '. $fileinfo[$fileinfo['fileformat']]['video']['color_depth'] .'-bit<br>';
  437. if(isset($fileinfo['tags_html'][$fileinfo['fileformat']]['author'][0]))
  438. echo 'Video author: '. $fileinfo['tags_html'][$fileinfo['fileformat']]['author'][0] .'<br>';
  439. echo '</td></tr>';
  440. }
  441. echo '</table>';
  442. echo '<a href="JavaScript:window.close()">Click here to close this window.</a>';
  443. } else {
  444. echo '<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td></td>';
  445. // <tr><td align="left"><img src="/icons/folder.open.gif"><a href="' . $parent_loc . $adlnk . '">Parent Directory</a></td>';
  446. echo '<td align="right">Search this directory <a href="" onClick="JavaScript:window.open(\''.$phpSelf.'?note=5\',\'note\',\'width=250,height=280,dependent=yes,location=no,scrollbars=yes,menubar=no,status=no,resizable=yes\')">(?)</a>: <form action="'.$phpSelf.'" method="get"><input type="text" maxlength="255" value="'.$search_value.'" name="search_value"><br>';
  447. if($showsearch)
  448. echo '<input type="checkbox" name="showsearch" value="1" checked>Show only search results?<br>';
  449. else
  450. echo '<input type="checkbox" name="showsearch" value="1">Show only search results?<br>';
  451. if($exactmatch)
  452. echo '<input type="checkbox" name="exactmatch" value="1" checked>Exact results only?<br>';
  453. else
  454. echo '<input type="checkbox" name="exactmatch" value="1">Exact results only?<br>';
  455. echo '<input type="hidden" name="loc" value="'.$loc.'">';
  456. if($search_value != 'Search')
  457. echo "<input type=\"button\" value=\"Clear Search\" onClick=\"JavaScript:location.href='$phpSelf?loc=$loc'\"> ";
  458. echo '<input type="submit" value="Search"></form>';
  459. echo '</td></tr></table>';
  460. if($search_value != 'Search')
  461. echo 'Search results are <b>bold</b>.<br><br>';
  462. echo "\n";
  463. echo '<table cellpadding="4" cellspacing="0" border="0">';
  464. echo '<tr><td></td><td><b>';
  465. if($ar1 == 'n' && $ar2 == 'a')
  466. echo "<a href=\"$phpSelf?loc=$loc$adlnk$adlnk2&arange=nd\">File Name</a>";
  467. else
  468. echo "<a href=\"$phpSelf?loc=$loc$adlnk$adlnk2&arange=na\">File Name</a>";
  469. echo '</b></td>';
  470. echo '<td align="center"><b>';
  471. if($ar1 == 's' && $ar2 == 'a')
  472. echo "<a href=\"$phpSelf?loc=$loc$adlnk$adlnk2&arange=sd\">Size</a>";
  473. else
  474. echo "<a href=\"$phpSelf?loc=$loc$adlnk$adlnk2&arange=sa\">Size</a>";
  475. echo '</b></td>';
  476. echo '<td align="center"><b>';
  477. if($ar1 == 't' && $ar2 == 'a')
  478. echo "<a href=\"$phpSelf?loc=$loc$adlnk$adlnk2&arange=td\">Type</a>";
  479. else
  480. echo "<a href=\"$phpSelf?loc=$loc$adlnk$adlnk2&arange=ta\">Type</a>";
  481. echo '</b></td><td></td>';
  482. if($show_add_info)
  483. echo '<td><b>Additional Info</b></td>';
  484. echo '<td></td>';
  485. echo '</tr>';
  486. $array_of_dirs = array();
  487. $array_of_files = array();
  488. $i = 0;
  489. $j = 0;
  490. // open the current directory
  491. if($handle = opendir($loc1 . $loc)){
  492. while(false !== ($file = readdir($handle))){
  493. // though this is kind of weird, I had the variables set up this way. I may change it in the future to get rid of one more line of code (mm optimization, tasty?)
  494. $file2 = $file;
  495. $file = $loc . $file;
  496. if(is_file($loc1 . $file) && !strstr(strtolower($file), 'filelist')
  497. && substr($file2, 0, 1) != '.' && !strstr($file, '..') && !strstr($file, '#') && $file2 != $cur_filename){
  498. // set use this to default, for whence it becomes 1 the loop will end
  499. $use_this = 0;
  500. // run through each acceptable extension
  501. for($k = 0; $k < count($accept) && $use_this != 1; $k++){
  502. // if the file has the correct extension, continue
  503. if(strtolower($accept[$k]) == strtolower(substr($file2, strlen($file2) - strlen($accept[$k]), strlen($accept[$k])))){
  504. // $organize_ord organizes the file names ignoring any leading 'the's and 'a's. With or without $organize_ord, the files are organized ignoring anything but letters and numbers
  505. if($organize_ord && strtolower(substr($file2, 0, 4)) == 'the ')
  506. $orgn = ereg_replace("[^[:alnum:]]", '', strtolower(trim(substr($file2, 3))));
  507. elseif($organize_ord && strtolower(substr($file2, 0, 2)) == 'a ')
  508. $orgn = ereg_replace("[^[:alnum:]]", '', strtolower(trim(substr($file2, 1))));
  509. elseif($organize_ord && strtolower(substr($file2, 0, 3)) == 'an ')
  510. $orgn = ereg_replace("[^[:alnum:]]", '', strtolower(trim(substr($file2, 2))));
  511. else
  512. $orgn = ereg_replace("[^[:alnum:]]", '', strtolower(trim($file2)));
  513. // determine the filetype, if there is no '.' or no extension in the filename, then return "none"
  514. $ftype = 'none';
  515. if(strstr($file2, '.')){
  516. $m = strlen($file2);
  517. while($m > 0 && $ftype == 'none'){
  518. $m--;
  519. if(substr($file2, $m, 1) == '.')
  520. $ftype = strtolower(substr($file2, $m + 1, strlen($file2)));
  521. }
  522. }
  523. // store file size (in bytes)
  524. $size = filesize($loc1 . $file);
  525. // the organization type determines the order in which the variables are stored
  526. if($ar1 == 'n'){
  527. $array_of_files[$j]['orgn'] = $orgn;
  528. $array_of_files[$j]['ftype'] = $ftype;
  529. $array_of_files[$j]['size'] = $size;
  530. } else
  531. if($ar1 == 't'){
  532. $array_of_files[$j]['ftype'] = $ftype;
  533. $array_of_files[$j]['orgn'] = $orgn;
  534. $array_of_files[$j]['size'] = $size;
  535. } else
  536. if($ar1 == 's'){
  537. $array_of_files[$j]['size'] = $size;
  538. $array_of_files[$j]['orgn'] = $orgn;
  539. $array_of_files[$j]['ftype'] = $ftype;
  540. }
  541. // these variables are last since they don't affect organization
  542. $array_of_files[$j]['file'] = $file;
  543. $array_of_files[$j]['file2'] = $file2;
  544. $array_of_files[$j]['extkey'] = $k;
  545. $j++;
  546. // get the heck out of the loop
  547. $use_this = 1;
  548. } // if(strtolower($accept[$k]) == strtolower(substr($file2, ...
  549. } // for($k = 0; $k < count($accept) && $use_this != 1; $k++)
  550. } // if(is_file($loc1 . $file) && substr($file2, 0, 8) != 'filelist' && ...
  551. else
  552. if(is_dir($loc1 . $file) && substr($file2, 0, 1) != '.'
  553. && !strstr(strtolower($file2), 'filelist') && substr($file2, 0, 6) != 'getid3'
  554. && substr($file2, 0, 12) != 'My Playlists' && !strstr($file2, '#')){
  555. // $organize_ord organizes the directory names ignoring any leading 'the's and 'a's. With or without $organize_ord, the directories are organized ignoring anything but letters and numbers
  556. if(strtolower(substr($file2, 0, 4)) == 'the ' && $organize_ord)
  557. $array_of_dirs[$i]['orgn'] = ereg_replace("[^[:alnum:]]", '', strtolower(trim(substr($file2, 3))));
  558. elseif(strtolower(substr($file2, 0, 2)) == 'a ' && $organize_ord)
  559. $array_of_dirs[$i]['orgn'] = ereg_replace("[^[:alnum:]]", '', strtolower(trim(substr($file2, 1))));
  560. else
  561. $array_of_dirs[$i]['orgn'] = ereg_replace("[^[:alnum:]]", '', strtolower(trim($file2)));
  562. // store directory name to array
  563. $array_of_dirs[$i]['file'] = $file;
  564. $array_of_dirs[$i]['file2'] = $file2;
  565. $i++;
  566. } // if(is_dir($loc1 . $file) && substr($file2, 0, 1) != '.' && ...
  567. } // while(false !== ($file = readdir($handle)))
  568. // close out of the directory
  569. closedir($handle);
  570. } // if($handle = opendir($loc1 . $loc))
  571. // if any directories were found, store them to $array_of_all
  572. if(@count($array_of_dirs) > 0){
  573. $u_array_of_dirs = $array_of_dirs;
  574. sort($array_of_dirs);
  575. $array_of_all = $array_of_dirs;
  576. }
  577. // if any files were found store that info to $array_of_all
  578. if(@count($array_of_files) > 0){
  579. $u_array_of_files = $array_of_files;
  580. if($ar2 == 'a')
  581. sort($array_of_files);
  582. else
  583. rsort($array_of_files);
  584. // if directories were already stored to $array_of_all, then store each file key to $array_of_all
  585. if(count($array_of_dirs) > 0){
  586. for($i = 0; $i < count($array_of_files); $i++){
  587. $j = count($array_of_all);
  588. $array_of_all[$j]['file'] = $array_of_files[$i]['file'];
  589. $array_of_all[$j]['file2'] = $array_of_files[$i]['file2'];
  590. $array_of_all[$j]['extkey'] = $array_of_files[$i]['extkey'];
  591. $array_of_all[$j]['size'] = $array_of_files[$i]['size'];
  592. $array_of_all[$j]['ftype'] = $array_of_files[$i]['ftype'];
  593. }
  594. } else
  595. $array_of_all = $array_of_files;
  596. // if no directories were stored, just store the files to $array_of_all
  597. }
  598. if(!isset($array_of_all))
  599. $array_of_all = array();
  600. // ready to display all the crap that was just stored
  601. foreach($array_of_all as $j => $file){
  602. $file = $array_of_all[$j]['file'];
  603. $file2 = $array_of_all[$j]['file2'];
  604. // this section is for files, later is for directories; also, exclude UNIX hidden files
  605. if(is_file($loc1 . $file)){
  606. // nice long test, so that it only does the things it needs to do, when it needs to do it; and if only the finds are to be shown, only they will be
  607. if(($showsearch == 1 && isclosematch($file2, $search_value, $exactmatch, 0)) || $showsearch != 1 || $search_value == 'Search'){
  608. $extkey = $array_of_all[$j]['extkey'];
  609. $ftype = $array_of_all[$j]['ftype'];
  610. $size = $array_of_all[$j]['size'];
  611. // if there is a file type then get the file's name (no extension)
  612. if($ftype != 'none')
  613. $name2 = substr($file2, 0, strlen($file2) - strlen($ftype) - 1);
  614. else
  615. $name2 = $file2;
  616. // if additional info is enabled, test each file to see if it can extract any info from it
  617. if($show_add_info){
  618. $add_info = '';
  619. // if the file is a text file, display some of it's contents
  620. if($ftype == 'txt' || $ftype == 'list' || $ftype == 'nfo'
  621. || $ftype == 'log' || $ftype == 'diz'){
  622. $contents = file($loc1 . $file);
  623. @$contents2 = $contents[0] . $contents[1] . $contents[2] . rtrim($contents[3]);
  624. $contlen = strlen($contents2);
  625. if($contlen > 40){
  626. $contlen = 40;
  627. $contover = true;
  628. } else
  629. $contover = false;
  630. $add_info = 'Number of lines: ' . count($contents) . '; <b>Contents:</b> ' . str_replace("\n", ' :: ', str_replace("\r", '', htmlspecialchars(substr($contents2, 0, $contlen))));
  631. if($contover)
  632. $add_info .= '...';
  633. } else
  634. // if the file is an HMTL file, display it's title, or body, or contents
  635. if($ftype == 'htm' || $ftype == 'html'){
  636. $titover = false;
  637. $bodover = false;
  638. $conover = false;
  639. if($php_version[0] > 4 || ($php_version[0] == 4 && $php_version[1] >= 3))
  640. $contents = file_get_contents($loc1 . $file);
  641. else {
  642. $array_of_contents = file($loc1 . $file);
  643. $contents = implode('', $array_of_contents);
  644. }
  645. $contents2 = strtolower($contents);
  646. if(strstr($contents2, '<title>')){
  647. $titlepos1 = 7 + strpos($contents2, '<title>');
  648. $contents2 = substr($contents2, $titlepos1);
  649. if(strstr($contents2, '</title>')){
  650. $titlepos2 = strpos($contents2, '</title>');
  651. if($titlepos2 > 40){
  652. $titlepos2 = 40;
  653. $titover = true;
  654. }
  655. $add_info = '<b>Title:</b> ' . htmlspecialchars(substr($contents, $titlepos1, $titlepos2));
  656. if($titover)
  657. $add_info .= '...';
  658. }
  659. } else
  660. if(strstr($contents2, '<body')){
  661. $bodypos1 = 6 + strpos($contents2, '<body');
  662. $contents2 = substr($contents2, $bodypos1);
  663. $bodypos3 = 1 + strpos($contents2, '>');
  664. $contents2 = substr($contents2, $bodypos3);
  665. if(strstr($contents2, '</body>')){
  666. $bodypos2 = strpos($contents2, '</body>');
  667. if($bodypos2 > 40){
  668. $bodypos2 = 40;
  669. $bodover = true;
  670. }
  671. $bodycont = substr($contents, $bodypos1 + $bodypos3, $bodypos2);
  672. $add_info = '<b>Body:</b> ' . str_replace("\n", ' :: ', str_replace("\r", '', htmlspecialchars($bodycont)));
  673. if($bodover)
  674. $add_info .= '...';
  675. }
  676. } else {
  677. $cont_len = strlen($contents);
  678. if($cont_len > 40){
  679. $cont_len = 40;
  680. $conover = true;
  681. }
  682. $add_info = '<b>Contents:</b> ' . str_replace("\n", ' :: ', str_replace("\r", '', htmlspecialchars(substr($contents, 0, $cont_len))));
  683. if($conover)
  684. $add_info .= '...';
  685. }
  686. } else
  687. if($ftype == 'php' || $ftype == 'php3' || $ftype == 'phtml'
  688. || $ftype == 'php5' || $ftype == 'php4')
  689. $add_info = 'Number of lines: ' . count(file($loc1 . $file));
  690. else
  691. // supported by 4.3.2: GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM, and WBMP
  692. if($php_version[0] > 4 || ($php_version[0] == 4 && $php_version[1] > 3) || ($php_version[0] == 4 && $php_version[1] == 3 && $php_version[2] >= 2))
  693. if($ftype == 'gif' || $ftype == 'jpg' || $ftype == 'jpeg'
  694. || $ftype == 'png' || $ftype == 'swf' || $ftype == 'swc'
  695. || $ftype == 'psd' || $ftype == 'tiff' || $ftype == 'bmp'
  696. || $ftype == 'iff' || $ftype == 'jp2' || $ftype == 'jpx'
  697. || $ftype == 'jb2' || $ftype == 'jpc' || $ftype == 'xbm'
  698. || $ftype == 'wbmp' || $ftype == 'tif')
  699. if($tmp = getimagesize($loc1 . $file))
  700. $add_info = 'Resolution: ' . $tmp[0] . 'x' . $tmp[1];
  701. else
  702. // supported by 4.3.0: GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, and IFF
  703. if($php_version[0] > 4 || ($php_version[0] == 4 && $php_version[1] >= 3))
  704. if($ftype == 'gif' || $ftype == 'jpg' || $ftype == 'jpeg'
  705. || $ftype == 'png' || $ftype == 'swf' || $ftype == 'swc'
  706. || $ftype == 'psd' || $ftype == 'tiff' || $ftype == 'bmp'
  707. || $ftype == 'iff' || $ftype == 'tif')
  708. if($tmp = getimagesize($loc1 . $file))
  709. $add_info = 'Resolution: ' . $tmp[0] . 'x' . $tmp[1];
  710. else
  711. // supported by 4.2.0: GIF, JPG, PNG, SWF, PSD, TIFF, BMP, and IFF
  712. if($php_version[0] > 4 || ($php_version[0] == 4 && $php_version[1] >= 2))
  713. if($ftype == 'gif' || $ftype == 'jpg' || $ftype == 'jpeg'
  714. || $ftype == 'png' || $ftype == 'swf' || $ftype == 'psd'
  715. || $ftype == 'tiff' || $ftype == 'bmp' || $ftype == 'iff'
  716. || $ftype == 'tif')
  717. if($tmp = getimagesize($loc1 . $file))
  718. $add_info = 'Resolution: ' . $tmp[0] . 'x' . $tmp[1];
  719. else
  720. // supported before 4.2.0: GIF, JPG, PNG, SWF, PSD, BMP, and IFF
  721. if($ftype == 'gif' || $ftype == 'jpg' || $ftype == 'jpeg'
  722. || $ftype == 'png' || $ftype == 'swf' || $ftype == 'psd'
  723. || $ftype == 'bmp' || $ftype == 'iff')
  724. if($tmp = getimagesize($loc1 . $file))
  725. $add_info = 'Resolution: ' . $tmp[0] . 'x' . $tmp[1];
  726. }
  727. // if getid3 is going to be called, set up $filename, then get info
  728. if($show_add_info && $getid3_true && ($add_info == '' || !isset($add_info))){
  729. $filename = $loc1 . $file;
  730. $getID3 = new getID3;
  731. $fileinfo = $getID3->analyze($filename);
  732. $add_info = '';
  733. if($getid3_true && isset($fileinfo['video']['codec'])){
  734. if(isset($fileinfo['bitrate']))
  735. $file_br = $fileinfo['bitrate'];
  736. if(isset($fileinfo['playtime_string']))
  737. $add_info = 'Length: ' . $fileinfo['playtime_string'] . '; ';
  738. $add_info = $add_info . 'Resolution: ' . $fileinfo['video']['resolution_x'] . 'x' . $fileinfo['video']['resolution_y'] . ';';
  739. if(isset($file_br))
  740. $add_info = 'Bitrate: ' . round($file_br / 1000) . ' kbps; Codec: ' . $fileinfo['video']['codec'];
  741. } else
  742. if($getid3_true && isset($fileinfo['audio']['bitrate'])){
  743. $file_br = $fileinfo['bitrate'];
  744. $add_info = 'Length: ' . $fileinfo['playtime_string'] . '; Bitrate: ' . round($file_br / 1000) . ' kbps';
  745. if($ftype == 'wma')
  746. $add_info = $add_info . ' (MP3 equiv: ' . round($file_br / 600) . ' kbps)';
  747. }
  748. }
  749. $file_size = filesz(filesize($loc1 . $file));
  750. echo "\n<tr><td><img src=\"$iconlink[$extkey]\"></td><td><a href=\"$cur_dir$file\">";
  751. // if there is a search occuring, and the test of the search string in the isclosematch() function returns true; then bold the name so it can be seen
  752. if($search_value != 'Search' && isclosematch($file2, $search_value, $exactmatch, !$exactmatch))
  753. echo "<b>$name2</b>";
  754. else
  755. echo $name2;
  756. echo '</a></td><td align="center">';
  757. echo $file_size . '</td>';
  758. echo '<td align="center">';
  759. echo $ftype . '</td><td align="center">';
  760. // if the file's creation time is newer than the current time - the "new time" deadline (set above in seconds) then display "new"
  761. if($display_new && filectime($loc1 . $file) > time() - $new_time_secs)
  762. echo '<font color="red">New</font>';
  763. elseif($display_updated && filemtime($loc1 . $file) > time() - $new_time_secs)
  764. echo '<font color="yellow">Updtd</font>';
  765. echo '</td>';
  766. if($show_add_info)
  767. echo '<td>' . $add_info . '</td>';
  768. $fileenc = str_replace('&', "%26", $file);
  769. echo '<td><a title="Get properties of file" href="" onClick="';
  770. echo "JavaScript:window.open('$phpSelf?loc=$loc&prop=$fileenc','properties','width=430,height=580,dependent=yes,location=no,scrollbars=yes,menubar=no,status=no,resizable=yes')";
  771. echo '">Prop</a></td></tr>';
  772. }
  773. } else
  774. // this section is for directories, previous was for files; also, exclude the '.' and '..' directories
  775. if(is_dir($loc1 . $file)){
  776. // if there is a search occuring, and the test of the search string in the isclosematch() function returns true, or not only search results are being displayed, or there is no search; then continue, so the results can be displayed
  777. if(($showsearch == 1 && isclosematch($file2, $search_value, $exactmatch, 0)) || $showsearch != 1 || $search_value == 'Search'){
  778. echo "\n<tr><td><img src=\"/icons/folder.gif\"></td><td><a href=\"$phpSelf?loc=.$file$adlnk\">";
  779. // if there is a search occuring, and the test of the search string in the isclosematch() function returns true; then bold the name so it can be seen
  780. if($search_value != 'Search' && isclosematch($file2, $search_value, $exactmatch, !$exactmatch))
  781. echo "<b>$file2</b>";
  782. else
  783. echo $file2;
  784. echo '</a></td><td colspan="2" align="center">Directory</td><td>';
  785. // if the directory has been modified since the deadline, then display it, if the directory is new, then display so, if not, then display "updated"
  786. if($display_new && filectime($loc1 . $file) > time() - $new_time_secs)
  787. echo '<font color="red">New</font>';
  788. elseif($display_updated && filemtime($loc1 . $file) > time() - $new_time_secs)
  789. echo '<font color="yellow">Updated</font>';
  790. echo '</td>';
  791. if($show_add_info)
  792. echo '<td></td>';
  793. echo '</tr>';
  794. }
  795. }
  796. }
  797. echo "\n</table>\n";
  798. // echo '<br><br><img src="/icons/folder.open.gif"><a href="' . $parent_loc . $adlnk . '">Parent Directory</a>';
  799. // this area scans all subdirectories and stores the amount of files, directories, filesize, and time stamp into a file for access later
  800. // depending on the amount of files and directories, this could be a very long processes, so it doesn't happen every time a page loads
  801. // based on a variable set at the beginning of this file, it makes this refresh based on the amount of files and directories
  802. // this all boils down to the custom recursive flscandir() function. View that furthur down to see what is actually happening
  803. // it then takes all this information and displays it at the bottom of the page
  804. if($show_all_stats){
  805. $get_new_info = 0;
  806. if(!is_dir('filelist/'))
  807. mkdir('filelist/');
  808. if(!is_file($logFile))
  809. $get_new_info = 1;
  810. else {
  811. $array_of_log_file = file($logFile);
  812. if(trim($array_of_log_file[0]) < time() - $update_log_sec)
  813. $get_new_info = 1;
  814. else {
  815. $number_of_dirs = trim($array_of_log_file[1]);
  816. $number_of_files = trim($array_of_log_file[2]);
  817. $total_file_size = trim($array_of_log_file[3]);
  818. $last_update = trim($array_of_log_file[0]);
  819. }
  820. }
  821. if($get_new_info == 1){
  822. $number_of_files = 0;
  823. $number_of_dirs = 0;
  824. $total_file_size = 0;
  825. $count = 0;
  826. flscandir('.');
  827. $fout = fopen($logFile, 'w');
  828. $fp = fwrite($fout, time() . $line_break . $number_of_dirs . $line_break . $number_of_files . $line_break . $total_file_size . $line_break);
  829. fclose($fout);
  830. $last_update = time();
  831. }
  832. $file_size = filesz($total_file_size);
  833. echo "<br><br>As of " . date("F d, Y H:i (O)", $last_update) . " there is a total of $number_of_dirs directories, containing $number_of_files files, with a total file size of $file_size\n\n";
  834. }
  835. }
  836. } else {
  837. if($php_version[0] < 4 || ($php_version[0] == 4 && $php_version[1] < 2)){
  838. echo 'Server\'s PHP version is too old. It must be at least 4.2.0.<br>';
  839. echo 'Visit <a href="http://www.php.net">PHP.net</a> to get the newest version.';
  840. }
  841. }
  842. // always display this info for obvious legal reasons
  843. //echo '<br><br><br><font size="-1"><a target="_blank" href="http://www.sourceforge.net/projects/filelist/">Bobb\'s File List System</a> version ' . $version . '.<br>';
  844. //echo '&copy; 2004-2005 Bobb\'s File List System Development Team.<br>';
  845. //echo 'These pages are licensed under the <a href="http://www.opensource.org/licenses/gpl-license.php" target="_blank">GNU General Public License</a>.<br>';
  846. //echo 'These pages and the software that generates them are NOT covered by any kind of warranty, either expressed or implied.<br>';
  847. //echo 'Redistribution is permitted under the same license.</font>';
  848. echo '</body></html>';
  849. /******************************************************************************
  850. * Below here are all the functions called by all the previous code. *
  851. ******************************************************************************/
  852. // function keeps track of page views and unique hits and logs them in a file
  853. // so they can be accessed later for statistics.
  854. // Some ideas and lines of code taken from OutSide Photos
  855. // (www.sourceforge.net/projects/outside-photos/) copyright 2004-2005 by
  856. // OutSide Photos Development Team under the GNU General Public License,
  857. // redistibution is allowed under the same licese. View the file LICENSE that
  858. // was packaged with this file, or download a copy at
  859. // www.opensource.org/licenses/gpl-license.php
  860. function hits(){
  861. // this keeps track of all the page views
  862. $pageviewsfile = 'filelist/pageviews.list';
  863. if(is_file($pageviewsfile)){
  864. $array_of_pageviews = file($pageviewsfile);
  865. $number_of_pageviews = $array_of_pageviews[0] + 1;
  866. $pageviewdate = $array_of_pageviews[1];
  867. } else {
  868. $number_of_pageviews = 1;
  869. $pageviewdate = time();
  870. }
  871. // fopen is set to w (instead of a) so that it will overwrite the previous value
  872. $fout = fopen($pageviewsfile, 'w');
  873. $fp = fwrite($fout, $number_of_pageviews . $GLOBALS['line_break'] . $pageviewdate);
  874. fclose($fout);
  875. // this keeps track of all unique hits
  876. if(isset($_SERVER['REMOTE_ADDR'])){
  877. $hitsfile = 'filelist/hits.list';
  878. if(is_file($hitsfile)){
  879. $array_of_hits = file($hitsfile);
  880. for($i = 1; $i < count($array_of_hits); $i++)
  881. $array_of_hits[$i - 1] = trim($array_of_hits[$i]);
  882. if(!in_array($_SERVER['REMOTE_ADDR'], $array_of_hits, true)){
  883. $fout = fopen($hitsfile, 'a');
  884. $fp = fwrite($fout, $_SERVER['REMOTE_ADDR'] . $GLOBALS['line_break']);
  885. fclose($fout);
  886. }
  887. } else {
  888. $fout = fopen($hitsfile, 'a');
  889. $fp = fwrite($fout, time() . $GLOBALS['line_break'] . $_SERVER['REMOTE_ADDR'] . $GLOBALS['line_break']);
  890. fclose($fout);
  891. }
  892. }
  893. } // end of hits()
  894. // takes $name and returns just the name of the file, no directories
  895. // also outputs $pre_ex as global for other uses
  896. function get_name($name){
  897. global $pre_ex;
  898. $pre_ex = '';
  899. if(substr($name, 0, 1) == '/')
  900. $name = substr($name, 1);
  901. if(strstr($name, '/')){
  902. for($i = strlen($name) - 1; $i >= 0; $i--){
  903. if(substr($name, $i, 1) == '/'){
  904. $pre_ex = substr($name, 0, $i + 1);
  905. return substr($name, strlen($pre_ex));
  906. }
  907. }
  908. }
  909. return $name;
  910. } // end of get_name()
  911. // Is this an acceptable file to do anything with? Does it comply with all
  912. // needs such as accepted extension and is not the current file. Does it have
  913. // anything to do with filelist?
  914. // returns true/false based on results
  915. function allowed($file, $dis_allowed_error, $dis_allowed_cont, $write_log){
  916. if(substr($file, 0, 1) != '/')
  917. if(substr($file, 0, 2) == './')
  918. $file = $GLOBALS['loc'] . substr($file, 2);
  919. else
  920. $file = $GLOBALS['loc'] . $file;
  921. if(!isset($GLOBALS['new_file']))
  922. $new_file = false;
  923. else
  924. $new_file = $GLOBALS['new_file'];
  925. if(isset($_POST['ren2'])
  926. || isset($_POST['cfname'])
  927. || isset($_FILES['userfile']))
  928. $new_file = true;
  929. if((is_file($GLOBALS['loc1'] . $file) || $new_file)
  930. && !strstr(strtolower($file), 'filelist') && !strstr($file, '..') && !strstr($file, '#') && $file != $GLOBALS['phpSelf'])
  931. if($GLOBALS['accept_all'])
  932. return true;
  933. else {
  934. foreach($GLOBALS['accept'] as $exts)
  935. if(strtolower($exts) == strtolower(substr($file, strlen($file) - strlen($exts), strlen($exts))))
  936. // get the heck out of the function
  937. return true;
  938. } // if(!$accept_all)
  939. if($dis_allowed_error)
  940. echo '<font color="red">This file ('.$file.') is off limits. If you believe this is in error, please contact the administrator of this site immidiately.</font><br><br>';
  941. if($dis_allowed_cont)
  942. echo '<a href="' . $GL

Large files files are truncated, but you can click here to view the full file