Script for creating url's

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
asai
Forum Commoner
Posts: 43
Joined: Tue May 04, 2010 6:24 am
Location: Norway

Script for creating url's

Post by asai »

Hi,
Is there a way to make a PHP script that checks a folder on the webserver, and creates links for the html pages in the folder?
The reason for this question is that I have a system that creates webpages with statistics. One new for each month. Now I once a month have to update the statistics page manually.
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: Script for creating url's

Post by Neilos »

You can read the files in a folder and print them into a list of links like...

Code: Select all

	if ($handle = opendir('directory/')) {
		echo "Files:<br />";
		$i = 0;
    		while (false !== ($file = readdir($handle))) {
			if ($file != "." && $file != "..") {
				echo $file;
				echo "<br />";
				$files_array[$i] = $file;
				$i++;
			}
		}
		foreach ($files_array as $value) {
			echo '<a href="www.yoursite.com/directory/' . $value . '">' . $value . '</a><br />';
		}
		closedir($handle);
	}
Post Reply