Phenomena Posted July 5, 2007 Share Posted July 5, 2007 Ok so what I'm trying to do is set up a directory that will contain a bunch of different web pages and have any web page in that one directory linked on the nav.php automatically. Lets say I have 3 files in my stuff/ directory, named file1.php, file2.php and file3.php. In the nav.php I want a script that will generate this html for every page <a href="/stuff/$file">$name</a> where $file is the file name in the directory, and $name is a variable defined within the file its self. Link to comment https://forums.phpfreaks.com/topic/58596-linking-to-all-files-in-a-directory/ Share on other sites More sharing options...
GingerRobot Posted July 5, 2007 Share Posted July 5, 2007 Well, generating a list of all the files in the directory is reasonably straight forward. Take a look at the examples on the php website for readdir() You could then use the fread() function to get the contents of each file and find your name. Link to comment https://forums.phpfreaks.com/topic/58596-linking-to-all-files-in-a-directory/#findComment-290649 Share on other sites More sharing options...
Phenomena Posted July 5, 2007 Author Share Posted July 5, 2007 thanks so much i got it working the only problem is that it also creates a link to the directory itself and to the sites homepage. Link to comment https://forums.phpfreaks.com/topic/58596-linking-to-all-files-in-a-directory/#findComment-290666 Share on other sites More sharing options...
GingerRobot Posted July 5, 2007 Share Posted July 5, 2007 You'll need to put in a little validation. Use something like this in your while loop: <?php if($file != '.' && $file != '..'){ echo $file; } ?> Link to comment https://forums.phpfreaks.com/topic/58596-linking-to-all-files-in-a-directory/#findComment-290671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.