vxdom Posted October 20, 2007 Share Posted October 20, 2007 Not sure if this is the right forum as I'm new, so I apologise in advanced if need be! I'm a real n00b to PHP. I'm looking for a little image gallery script that will show all the images in one folder, take a description from a text file and create a page like this: <div>{title of directory1}<img src="{thumb.jpg from directory1}" /></div> <div>{title of directory2}<img src="{thumb.jpg from directory2}" /></div> <div>{title of directory3}<img src="{thumb.jpg from directory3}" /></div> Which would link to show the contents as: <div>{text from chosen directory/description.txt}</div> <div>{title of chosen directory}</div> <div>{image#1}{image#2}{image#3}{image#etc}</div> So.. Trees (image of a tree) Benches (image of a bench) Clouds (image of a cloud) Which would link to: Here are some photos I have taken of Trees. Trees (image of tree1) (image of tree2) (image of tree3) I've been told this is a simple enough thing to do so if anyone could help me out that'd be ace, Thanks a lot. Dom! Link to comment https://forums.phpfreaks.com/topic/74126-looking-for-a-small-script/ Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 /** * Create a Directory Map * * Reads the specified directory and builds an array * representation of it. Sub-folders contained with the * directory will be mapped as well. * * @access public * @param string path to source * @param bool whether to limit the result to the top level only * @return array */ function directory_map($source_dir, $top_level_only = FALSE) { if ($fp = @opendir($source_dir)) { $filedata = array(); while (FALSE !== ($file = readdir($fp))) { if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE) { $temp_array = array(); $temp_array = directory_map($source_dir.$file."/"); $filedata[$file] = $temp_array; } elseif (substr($file, 0, 1) != ".") { $filedata[] = $file; } } return $filedata; } } This'll grrab everything in a directory. Then just make them into images (easy) Link to comment https://forums.phpfreaks.com/topic/74126-looking-for-a-small-script/#findComment-374360 Share on other sites More sharing options...
kratsg Posted October 20, 2007 Share Posted October 20, 2007 Here's a simpler version, if you know the directories (or can at least put them in an array) $directory = array("directory1","directory2","directory3"); foreach($directory as $dir){ $pattern = "$dir/*.(gif|jpg|jpeg|png)";//may need to modify it for the images, but it should work $files[] = glob($pattern); } print_r($files); The glob() function is basically like a preg_match, in which you supply a pattern, it searches the path you give it, and returns all the files (in an array basically, per directory). Link to comment https://forums.phpfreaks.com/topic/74126-looking-for-a-small-script/#findComment-374371 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.