Jump to content
xisto Community
Sign in to follow this  
itssami

How To Access A Folder In Php Page

Recommended Posts

I have a folder on my hosting space..(i.e. public_html), i want to add this folder on my php page.., . how it should be done that, when i add some file in the folder using ftp or anything , the folder on that page automatically includes that file.for example , if the folder has 5 files..and on page it says "folder has 5 files"and shows the files...and when i have uploaded 2 more files ,it should automatically say that folder has 7 files..

Share this post


Link to post
Share on other sites

Look at the php.net site for the functions relating to directories such as isdir(), readdir().Simply read the contents of the directory while looping and count the number of files, then echo or print the results. Exclude the sub-directories while looping.That is a rough outline of the the pseudo-code to perform the task. I think I have a script which might need some changes to it in order to do exactly what you want. Do you code in php? If so, PM me and I'll see if I can find it to send to you.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"		"http://forums.xisto.com/no_longer_exists/ xmlns="http://www.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="http://forums.xisto.com/no_longer_exists/ the xhtml</a>  </p>  </body></html>

This script lists the files as links. You will have to Mod it to count the files and echo the results of the count. And add the CSS styling for the UL and LI's , etcetera. Not a biggie.

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.