Created
August 7, 2012 20:27
-
-
Save adrian7/3289019 to your computer and use it in GitHub Desktop.
Finder.php - find files with php
This file contains hidden or 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
<style type="text/css"> | |
body, button, input{ | |
font-size:130%; | |
font-family:Verdana, Arial, Helvetica, sans-serif; | |
} | |
</style> | |
<?php | |
define('SPATH', dirname(__FILE__)); | |
define('SBURL', str_replace('/finder.php', '', $_SERVER['REQUEST_URI'])); | |
if(!class_exists('RecursiveDirectoryIterator')) die("RecursiveDirectoryIterator class not available!"); | |
if( strlen($_POST['filename']) ){ | |
$Tree = new RecursiveDirectoryIterator(SPATH); | |
$count=0; | |
foreach(new RecursiveIteratorIterator($Tree) as $path) { | |
$filename = basename($path); | |
if( $_POST['filename'] == $filename ){ | |
$fileurl = ( SBURL . str_replace(SPATH, "", $path) ); | |
echo '• <a href="' . $fileurl . '">' . $fileurl . '</a><br/>'; | |
} | |
} | |
} | |
?> | |
<?php if(empty($_POST)): ?> | |
<form name="finder-form" id="finder-form" method="post" target="_self"> | |
<p> | |
<label for="dir">Current dir:</label> | |
<strong><?php echo SPATH; ?></strong> | |
</p> | |
<p> | |
<label for="filename">Filename to search for:</label> | |
<input type="text" name="filename" id="filename" size="50" maxlength="255" value="<?php echo stripslashes($_POST['filename']); ?>"/> | |
</p> | |
<p align="center"> | |
<button type="submit"> GO </button> | |
</p> | |
</form> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment