Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-06-2012, 12:51 PM   #1
New Member
 
Join Date: Feb 2012
Posts: 2
Default Dynamic menu building

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
Morningstar is offline   Reply With Quote


Old 02-08-2012, 08:05 PM   #2
Gold Member
 
Join Date: Nov 2009
Location: New York
Posts: 370
Default

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>';
	}
__________________
Submit to my Website Gallery | NY Web Design
bcee is offline   Reply With Quote
Old 02-13-2012, 01:16 PM   #3
New Member
 
Join Date: Feb 2012
Posts: 2
Default Thank you

Thanks for the code. I'll try it out. I'll let you know what happens.
Morningstar is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 07:16 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.