|
|
#1 |
|
New Member
![]() Join Date: Feb 2012
Posts: 2
|
Hi everyone,
These might be noob questions, but if you don't ask you never learn. I'm trying to get a site to dynamically build a menu based on the number of files in a folder. For example, I have 6 files in my folder images. I would therefore like a menu with 6 links. If I place a new image in the folder the list should have 7 links. The next thing is that these images should be loaded into a viewer (I usually use an I frame so I don't have to reload the entire page). Does anyone know how to do this? I prefer doing this is PHP as I do know how this works, but it's been a very long time since I've actually needed to create something. Thanks, Paul |
|
|
|
|
|
#2 |
|
Gold Member
![]() Join Date: Nov 2009
Location: New York
Posts: 370
|
You could use php to parse the file structure of a given directory and output the filenames.
I used a simple script to parse a directory named 'img' and echo the results. Maybe it will help. Code:
if(!isset($_GET['design'])) {
// if no get data we will display a list of the image directory
if($handle = opendir('img')) {
echo '<h2>Designs</h2><br />';
while(false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo '<a href="' . $_SERVER['PHP_SELF'] . '?design=' . $file . '">' . $file . '</a><br />';
}
}
closedir($handle);
}
} else {
// display image
echo '<div class="design" style="background: url(img/' . $_GET['design'] . ') top center no-repeat;"></div>';
}
|
|
|
|
|
|
#3 |
|
New Member
![]() Join Date: Feb 2012
Posts: 2
|
Thanks for the code. I'll try it out. I'll let you know what happens.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|