Jump to content

list of files from root directory?


dmccabe

Recommended Posts

I am just playing php, html and css and want to create page where the user can select different css styles to apply to the site.

 

I have already made the site and created 2 different css files an have even managed to make it so the user can select css 1 or css 2, click submit and it applies it to the site.

 

However what would be better is if it could read the list of css files from the root directory and populate the drop down list.

 

I did find an example of a php script to list files, but couldn't work out what exactly it was doing so would prefer to learn it properly.

 

Any takers to give me a well coded example?

Link to comment
https://forums.phpfreaks.com/topic/95495-list-of-files-from-root-directory/
Share on other sites

Update...lol (it's always the same I look at a problem for hours then just after posting I work it out lol).

 

Anyways, using the example I found on the web for getting the list of files, I did this:

 

			<? if ($handle = opendir('.')) {
				while (false !== ($file = readdir($handle)))
					{
						if ($file != "." && $file != "..")
							{
								$thelist .= '<a href="'.$file.'">'.$file.'</a>';
								echo "<option value=\"$file\">$file</option>";

							}
					}
				closedir($handle);
			}
?>

 

Which does almost what I want, except it lists all the files not just the .css files.

 

Now my question is how do you do a wilcard match in php ? so I can check if $file = *.css or the equivalent.

Thanks for the replies guys.

 

Charlie, yours did the trick nicely, but I think thorpe's would be the correct way if trying to keep to good coding standards.

 

That said I am very new to PHP, html and CSS so would appreciate it if you could explain your code a little Thorpe?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.