Jump to content
xisto Community
Sign in to follow this  
jlhaslip

Php Script To Make A Link List From the list of the Directory Files

Recommended Posts

Well, it has been a while since I have added anything to the Tutorial Sectiion, so here is another script for the members to enjoy.This one creates a list of links from the contents of the directory which it is run from. For instance, if you run it from the public_html folder, then all the files (not the Directores) are listed and linked so when you click on the link, that file is parsed and output to the browser.Here is the code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;<html xmlns="w3.org/1999/xhtml/; xml:lang="en" lang="en"><head> <title>An XHTML 1.0 Strict Page to List the files in this directory</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /></head><body> <p>... Your HTML content here ...</p> <?php//dir_list.php$default_dir = "./"; // lists files only for the directory which this script is run fromecho '<div id="link_div"><ul>' . "\r\n\t";if(!($dp = opendir($default_dir))) die("Cannot open $default_dir.");while($file = readdir($dp)) { if(is_dir($file)) { continue; } else if($file != '.' && $file != '..') { echo '<li><a href="' . $file . ' " class="link_li" >' . $file . '</a></li>' . "\r\n\t"; }}closedir($dp);echo '</ul> </div>';?> <p>... Your HTML content here ...</p> <p> <a href="validator.w3.org/check?uri=referer the xhtml</a> </p> </body></html>

If you save it as the index.html file for the public_html folder of your account and alter the .htaccess file for the account to parse html as php, then the script will list out all the files in the folder as links. Alternately, if you use it as a page on your site, then it will create a 'sitemap' of all the files in that folder.Use it freely. I hope it helps someone. Enjoy.


Share this post


Link to post
Share on other sites

I think this is a pretty cool script. Thanks for sharing it. :lol: But i think it is not right for a Sitemap because many people have filenames that wouldnt look good for a sitemap. But surely its usefull if someone wants to make a filemanager or somehting an is just learning php. It would be intresting to see how this works with listing subfolders and the files under it. Then if someone made the right filenames and you made it filter out all files except html and php files and remove the extension from the end it would be pretty nice.

Share this post


Link to post
Share on other sites

Yes, those are all good characteristics of a file manager/sitemap script. One of the issues which determines the scripts I post in the Tutorial Section is their relative in-completeness. This allows users to customize them and develop their own php scripting abilities. This script is in no way complete, I agree, but maybe someone would be able to use it and expand it with their own enhancements to do exactly what they want.

Share this post


Link to post
Share on other sites

another cool script. I haven't really had the need to have a file manager styled php code yet, although If I decide to do it in the future, this code will most certainly help.I'm sure though that with a little bit of modification to the code by another php user, this code will be professional and contain many new enhancements.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.