Page 1 of 1

Script for creating url's

Posted: Sun Sep 25, 2011 2:51 am
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.

Re: Script for creating url's

Posted: Sun Sep 25, 2011 4:42 am
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);
	}