PDA

View Full Version : Reading folders on my website.


24-ba
12-01-2004, 04:14 PM
This may be an easy thing for you PHP guru's but I was woundering how to read the folders on my site and then making PHP write url's and reading the files inside and making a menu from them for the folders such as:

Folders
Home >> resume.html, oldwesbites.html
Links >> games.html, news.html
About Me >> biography.html, pictures.html

URL
home.html
Left Menu
home/resume.html
homeoldwebsites.html

URL
links.html
Left Menu
links/games.html
links/news.html

URL
aboutme.html
Left Menu
about me/biography.html
about me/pictures.html

Now I'm not trying to get someone to write the code for me, but to help me if the functions I need to use. Many thanks.

xiaodao
12-01-2004, 04:56 PM
my script, very raw, it is a function call show link which will show all the files within the folder you specify with the filename as the link name

<?php
function showlink($directory) {
$d = dir($directory);
while (false !== ($entry = $d->read())) {
list($name,$ext)=explode(".",$entry);
if ($entry !='.'){
if ($entry != '..'){
echo "<a href=".$directory."/".$entry.">".$name."</a><br>";
}
}
}
$d->close();
}
?>

so if you want to show which folder, you can just enter the name like
showlink(main);
showlink(others);
etc.
and remember to place the script one root up the folder you want to show

24-ba
12-01-2004, 08:22 PM
I understand most of it except "explode" and as well I can't get it to work. But thanks alot. Possibly I could ask how to write everything in the directory and then go from there. And go from there would mean reading the files as strings and writing only the words that end in .html will be written in a url for the left bar.

xiaodao
12-02-2004, 12:18 AM
hmmm, be sure to put it like this
if you got one folder call news then inside got another folder call admin
then if you want to read the files in side folder of admin
then you put the script in the folder news, same level as folder admin

for me, it works very well, when i put
<?
showlinke(admin);
?>

the explode is to get the filename

24-ba
12-02-2004, 12:42 AM
is there no "" around admin? Because admin is returned as a string is it not?

xiaodao
12-02-2004, 12:55 AM
hmmmmm, i did not put the "" around admin, what is your error message. the admin is a value for $directory

24-ba
12-02-2004, 01:00 AM
there is no error message, it's just blank,even though the directory and folder inside are not empty.

Fou-Lu
12-02-2004, 02:04 AM
I'm a little confused here, your structure looks like so:
-home
--resume.html
--oldwebsites.html
-links
--games.html
--news.html
-aboutme
--biography.html
--pictures.html

And then in your home.html you want to convert your 'Left Menu' to include those links for instance?
If so, I would say your easiest way to control this is to use php as your pages in the first place, so you would want to change home.html to home.php, so you can use whatever functions you would like.
If this is what you need, then we can develop a simple function for you to do this with.

xiaodao
12-02-2004, 03:10 AM
there is no error message, it's just blank,even though the directory and folder inside are not empty.
now i am not at home, cannot test on my site, can show me the page?

24-ba
12-02-2004, 12:59 PM
I'm a little confused here, your structure looks like so:
-home
--resume.html
--oldwebsites.html
-links
--games.html
--news.html
-aboutme
--biography.html
--pictures.html

And then in your home.html you want to convert your 'Left Menu' to include those links for instance?
If so, I would say your easiest way to control this is to use php as your pages in the first place, so you would want to change home.html to home.php, so you can use whatever functions you would like.
If this is what you need, then we can develop a simple function for you to do this with.


That's exactly what I want. There will me 6 main pages for an example let's use biography.html. There will be a corresponding folder to that that says biography and all the html files in that folder, I will want to have show up on the left menu with all my code. ANd then for the sites inside that folder, for their left menu, it should be all the html files in that folder so:

biography.html --> biography/pictures.html
--> biography/videos.html
videos.html --> pictures.html
--> videos.html
pictures.html --> pictures.html
--> videos.html

the "-->" indicates what I want as a link in my left menu.

xiaodao
12-02-2004, 01:19 PM
hmmmm, i checked my script again, nothing wrong
the script works on my stie