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
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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.