PHP - Directory Listing
Just thought I'd end the night with a simple script. This PHP script will list all file, directory, and sub directories, and will even make links out of them.
PHP:
-
<p id="innersource" class="nowrap">
-
<pre class="php">//define the path as relative
-
-
$path = "/home/yoursite/public_html/whatever";
-
-
//using the opendir function
-
-
$dir_handle = @<a href="http://www.php.net/opendir">opendir</a>($path) or <a href="http://www.php.net/die">die</a>("Unable to open $path");
-
-
<a href="http://www.php.net/echo">echo</a> "Directory Listing of $path<br/>";
-
-
//running the while loop
-
-
while ($file = <a href="http://www.php.net/readdir">readdir</a>($dir_handle))
-
-
{
-
-
//encode spaces
-
-
$file = <a href="http://www.php.net/rawurlencode">rawurlencode</a>($file);
-
-
// convert the + (this is one result from the function rawurlencode) in %20
-
-
$url = <a href="http://www.php.net/str_replace">str_replace</a>('+' , '%20' , $file);
-
-
<a href="http://www.php.net/echo">echo</a> "<a href='".$url."'>".$url."</a><br/>";
-
-
}
-
-
//closing the directory
-
-
<a href="http://www.php.net/closedir">closedir</a>($dir_handle);</pre>








(No Ratings Yet)





















mike james said,
Wrote on March 6, 2008 @ 2:25 am
Be the first to join our brand new SEO oriented directory
and enjoy our amazing limited time offer.
Visit our website: http://www.directorymh.com and don't forget to tell your friends.
Directorymh team.