Hey,
I have written a Directory listing script, Which is in a function with the 3rd argument of the function being $showdir
eg: function displayFiles ($path, $extension, $showdir)
then its called like:
displayFiles ("/home/wwwroot/curves/wallpapers", "jpg", "0");
I wish to be able to choose whether or not to display dirs, Thats wat the 3rd argument is for($showdirs)...
If anyone can tell me how with an if/else condition i can do
if($showdir == 1)
Any ideas on the code to display or not to display dirs?
Need help with directory listings and dirs
Moderator: General Moderators
Directory listing script
i would loop through the listing and do a
the is_dir() function is doc'd at :
http://www.php.net/manual/en/function.is-dir.php
Code: Select all
if(!is_dir(їfile_or_directory_name])){echo їfile_or_directory_name];}http://www.php.net/manual/en/function.is-dir.php
- sam
- Forum Contributor
- Posts: 217
- Joined: Thu Apr 18, 2002 11:11 pm
- Location: Northern California
- Contact:
Code: Select all
if(!is_dir(їfile_or_directory_name]) || $isdir == 1){
echo їfile_or_directory_name];
}Cheers Sam
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
ok, the final answer:
function start :::
::: loop through directoy listing, and use this to check
::: end loop
end function :::
if $showdir is set to 1, it will display all entries, including directories, if not, it will ignore directories (i.e. entries that return false from the is_dir()).
the way that hob_goblin indicated will work, but why have an extra if...else? If hob_goblin's way is easier for you, use the code block that i put in the first response.
that either helped, or confused the hell out of you. good luck.
-c.w.collins
function start :::
Code: Select all
function whatever($directory,$extention,$showdir){Code: Select all
if(!is_dir(їfile_or_directory_name]) || $showdir == 1){
echo їfile_or_directory_name];
}Code: Select all
}if $showdir is set to 1, it will display all entries, including directories, if not, it will ignore directories (i.e. entries that return false from the is_dir()).
the way that hob_goblin indicated will work, but why have an extra if...else? If hob_goblin's way is easier for you, use the code block that i put in the first response.
that either helped, or confused the hell out of you. good luck.
-c.w.collins