PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/filelist.php

https://github.com/aeonofdiscord/love-webplayer
PHP | 27 lines | 13 code | 1 blank | 13 comment | 1 complexity | e8dac621aac95e5b86473ca0c1d26b55 MD5 | raw file
  1. <?php
  2. //~ for ($j=0;$j<1000;++$j) {
  3. //~ $num = rand() % 1000;
  4. //~ $arr1 = array();
  5. //~ $arr2 = array();
  6. //~ for ($i=0;$i<$num;++$i) { $k = rand()."abc$i"; $v = rand(); $arr1[$k] = $v; $arr2[$k] = $v; }
  7. //~ foreach ($arr1 as $k => $v) { if ((rand() % 5) < 1) { $arr1[$k."baazaaam"] = $v; $arr2[$k."baazaaam"] = $v; } else { $arr1[$k] = $v + 1; } } // FAIL! insert-during-iterate
  8. //~ foreach ($arr1 as $k => $v) { if ((rand() % 5) < 1) { unset($arr1[$k]); unset($arr2[$k]); } else { $arr1[$k] = $v + 1; } } // success
  9. //~ foreach ($arr2 as $k => $v) if ($arr1[$k] != $v+1) DIE("FAIL!");
  10. //~ }
  11. //~ DIE("SUCCESS!");
  12. function glob_recursive($pattern, $flags = 0,$prefix_remove=false,$prefix_add=""){//http://www.php.net/manual/en/function.glob.php#106595
  13. $files = glob($pattern, $flags);
  14. $prefix_remove_len = $prefix_remove ? strlen($prefix_remove) : 0;
  15. foreach ($files as $k => $file) $files[$k] = $prefix_add.substr($file,$prefix_remove_len);
  16. foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir){
  17. $files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags,$prefix_remove,$prefix_add));
  18. }
  19. return $files;
  20. }
  21. $game = isset($_GET['game'])?$_GET['game']:false;
  22. //~ $game = "iyfct";
  23. if (!file_exists(($game?$game:".")."/main.lua")) DIE("ERROR:no main.lua, file listing blocked\n");
  24. $arr = glob_recursive(($game?$game:".")."/*",0,($game?$game:".")."/","./");
  25. foreach ($arr as $ele) echo "$ele\n";
  26. ?>