houndcomputers Posted September 29, 2011 Share Posted September 29, 2011 I have a slideshow that I am having to modify for my needs. The data file uses an array and i need this to be dynamic. I need to loop through all images in a directory and create the array. I have the directory being stored in a variable already. Now i just need to loop though all images in that directory to create the array like you see in the below code. You can also see the directory variable at the top. Can someone give me a hand with this please? <?php echo $slideimagefolder; //http://localhost:82/images/groupphotos/1/1/ $slides = array( // --- Start slide list --- // slide elements array( "slidelink" => "http://www.frontpageslideshow.net", "title" => "Frontpage Slideshow 1.7", "category" => "About Frontpage Slideshow", "tagline" => "Image taken from the movie \"Shoot 'em up\"", "text" => "\"Frontpage SlideShow\" is the most eye-catching way to display your featured articles, stories or even products in your php based website or CMS, like Time.com, Joost.com or Yahoo! Movies do. \"Frontpage SlideShow\" creates an uber-cool slideshow with text snippets laying on top of images. These \"slides\" are being rotated one after the other with a nice fade effect. The slideshow features navigation and play/pause buttons, so the visitor has complete control over the slideshow's \"playback\"! And best of all, Frontpage Slideshow can be skinned!", "slideimage" => "ao4.jpg" ), // slide elements array( "slidelink" => "http://www.frontpageslideshow.net", "title" => "Use Frontpage Slideshow on any PHP based site!", "category" => "About Frontpage Slideshow", "tagline" => "Image taken from the movie \"The Kingdom\"", "text" => "JoomlaWorks has developed this modification of Frontpage Slideshow to work on every website that supports PHP as a minimum requirement. We call this modification the \"Static PHP\" version of Frontpage Slideshow. It's ideal for use on non-Joomla!/Mambo websites, like for example your corporate PHP based website or your Wordpress blog or Drupal website! You can obviously use this version on any CMS that is based on PHP!", "slideimage" => "the_kingdom_20070820114258369.jpg" ), // slide elements array( "slidelink" => "http://www.frontpageslideshow.net/content/view/14/37/", "title" => "FPSS is Search Engine Friendly!", "category" => "About Frontpage Slideshow", "tagline" => "Image taken from the movie \"Invaders\"", "text" => "Unlike Flash based slideshows, Frontpage Slideshow uses unobtrusive javascript and some CSS wizardry only. The content of the slides is laid out as html code, which means it can be \"read\" by search engines. The proper usage (and order) of h1, h2, p (and more) tags will make sure Google (or any other search engine) regularly \"scans\" your latest/featured items.", "slideimage" => "TVD_TR_02183_2.jpg" ), // slide elements (***TIP***: copy this data block and paste it below itself to add more slides) array( "slidelink" => "http://www.joomlaworks.gr", "title" => "About JoomlaWorks", "category" => "", "tagline" => "Image taken from the movie \"Transformers\"", "text" => "JoomlaWorks is a team of professional web designers and developers dedicated to delivering high-quality extensions and templates for Joomla! (the most popular open source Content Management System (CMS) worldwide) and Mambo (award winning CMS). JoomlaWorks has established a solid reputation in the Joomla! & Mambo communities, having developed some of the most popular and innovative free & commercial extensions & templates, since 2006.", "slideimage" => "2007_transformers_014_1.jpg" ), // --- End slide list --- ); ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 29, 2011 Share Posted September 29, 2011 And where is the data in the array supposed to be coming from? Seems like the best way to do this would be to store the info in a database, and just query it to build the array to feed to the slideshow. Quote Link to comment Share on other sites More sharing options...
xyph Posted September 29, 2011 Share Posted September 29, 2011 You may want to post this in 3rd part scripts or the FrontPage Slideshow's forum. Quote Link to comment Share on other sites More sharing options...
houndcomputers Posted September 29, 2011 Author Share Posted September 29, 2011 And where is the data in the array supposed to be coming from? Seems like the best way to do this would be to store the info in a database, and just query it to build the array to feed to the slideshow. All i need in the array for this particular application is the image itself. So , we have the directory the images are in. We loop through these and build the array with all the other items null. I can loop through and pull the image names easy enough. My problem is when i put $slides = array( foreach ($images as $image and try to loop though and build the array elements i get code format errors. Apparently after $slides = array( php does not expect a loop or any other code besides the array element itself. Does this make sense? I cant put all of it in a for loop because then i would create multiple $slides arrays instead of a single $slides array with multiple array elements. Quote Link to comment Share on other sites More sharing options...
houndcomputers Posted September 30, 2011 Author Share Posted September 30, 2011 Any idea on how to achieve this? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 30, 2011 Share Posted September 30, 2011 There's somewhat of a disconnect between what you're asking and the code you've posted. Because of that, I really don't follow what it is you're trying to do. Quote Link to comment Share on other sites More sharing options...
houndcomputers Posted September 30, 2011 Author Share Posted September 30, 2011 I have done a bit of research and figured out how to accomplish this. Here is the code $slides = array(); //echo $slideimagefolder; //http://localhost:82/images/groupphotos/1/1/ $findme = 'thumb_'; function dirImages($dir) { $d = dir($dir); //Open Directory while (false!== ($file = $d->read())) //Reads Directory { $extension = substr($file, strrpos($file, '.')); // Gets the File Extension if($extension == ".jpg" || $extension == ".jpeg" || $extension == ".gif" |$extension == ".png") // Extensions Allowed $images[$file] = $file; // Store in Array } $d->close(); // Close Directory asort($images); // Sorts the Array return $images; //Author: ActiveMill.com } $array = dirImages($AbsImageFolder); foreach ($array as $key => $image) // Display Images { $pos = strpos($image, $findme); if ($pos === false) { //echo $image; // slide elements $slides[] = array( "slideimage" => $image ); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.