Skip to content

Instantly share code, notes, and snippets.

@adrian7
Created August 7, 2012 20:27
Show Gist options
  • Save adrian7/3289019 to your computer and use it in GitHub Desktop.
Save adrian7/3289019 to your computer and use it in GitHub Desktop.
Finder.php - find files with php
<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 '&bull; <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