PHP help, someone?
- Started
- Last post
- 5 Responses
- schjetne
As some of you may (or may not) recall, I had some php file listing trouble some time ago.
I wanted a way to list documents in a directory, link to them, strip underscores and extension, and make a neat little menu out of it. Well, I finally finished that one. Now my boss is asking me for a little sumthin extra on this particular solution.
He wants me make a script that reads a directory, and if there is a subdirectory in that directory, it writes the name of that subdirectory, and then the names of the documents in that subdirectory, while at the same time listing the files in the main directory right beneath the subdirectory list...
Anyone know where to start?
Here's the code I use for reading the files in a directory now:
if ($dir = @opendir("../nyheter")) {
while (($file = readdir($dir)) !== false) {
$ext = strrchr($file,'.');
if ($file=="." or $file=="..") continue;
if ($ext == "") continue;
echo " <a href='../nyheter/$file'>";
print(str_replace(array('_', $ext)," ",$file));
echo "</a> < br > ";
}
closedir($dir);
}The downside with this in my new mission, is that I have to know the name of the subdirectory I list files from...
Thanks in advance for your help!
- anno0
I think you can use
is_dir (http://www.php.net/manual/en/fu...
so that when you loop through the files in a directory you can see if any of them are actually directories. if so then append the file to your base dir and open that one to list the contents of it.
Hopefully this helps!
- schjetne0
http://www.schjetne.net/mooh/treā¦
Here's what I've got so far. Now how do I go about to make the level 2 directories list INSIDE the level 1 directories instead of beneath?
PS: Click each directory to see the files inside.
- schjetne0
Enobrev:
Did you get my e-mail?
- enobrev0
lookin it over now man
- schjetne0
Enobrev, thanks!
I just answered your e-mail. A quick question, only.