Created
September 24, 2012 07:37
-
-
Save mrgenixus/3774786 to your computer and use it in GitHub Desktop.
Random file I found on desktop...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Template Name: Directory Listing | |
*/ | |
$dr = realpath(dirname($_SERVER['SCRIPT_FILENAME'])); | |
$document_root = realpath($_SERVER['DOCUMENT_ROOT']); | |
function relpath($path = null) { | |
global $dr, $document_root; | |
if ($path == null || ! strstr(($path = realpath($path)),$document_root) || ! strstr($path,$dr)) return "."; | |
return str_replace($dr . "/", "",$path); | |
} | |
$names = scandir($dir_name = relpath($_GET['dir'])); | |
if(count($names)): | |
?><ul><?php | |
foreach($names as $file) { | |
$truefile = relpath($dir_name . "/" . $file); | |
echo "<!--\n"; | |
echo "file: " . $file . "\n"; | |
echo "truefile: " . $truefile . "\n"; | |
echo "relative path: " . relpath($truefile) . "\n"; | |
echo "realpath: " . ($path = realpath($truefile)). "\n"; | |
echo "Script Root: " . $dr . "\n"; | |
echo "-->\n"; | |
if(is_dir($truefile)) { | |
echo "<!-- Is dir!! -->\n"; | |
if ($file != "." && $truefile != ".") { | |
?><li><a href="?dir=<?php echo (($file == "..") ? $file : $truefile); ?>"><?php echo $file; ?></a></li><?php | |
} | |
else echo "<!-- condition check failed $truefile, $file -->\n"; | |
} | |
else { | |
if(realpath($file) != realpath($_SERVER['SCRIPT_FILENAME'])): | |
?><li><a href="<?php echo $truefile; ?>"><?php echo $file; ?></a></li><?php | |
endif; | |
} | |
} | |
?></ul><?php | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment