By visiting our site, you agree to our privacy policy regarding cookies, tracking statistics, etc.

proper noun logo blue
  • Content Marketing
    • SEO Articles
    • Pillar Content
    • Website Content
    • Content Briefs
  • Off-Page
    • Managed Outreach
  • Optimization
    • Content Optimization
    • Technical SEO
  • Verticals
    • Ecommerce SEO Services
    • SaaS SEO Services
    • Enterprise Business SEO
    • Local SEO Services
  • Case Studies
  • Support
The Roadmap
Book A Demo
November 7, 2019by adamUncategorized

Php Tutorial: Getting All Files Within A Directory and Echoing In A Page

This post will cover getting all of the files as an array and then echoing them in a web page. In this example we will be using it to populate a slider with all of the images within a website subdirectory ‘/images/’.

The first things you will need to have is your slider set up, and all of the images you will be using in the ‘/images/’ folder. For the purposes of this example, this will be the markup for the slider:

<div id=”slider”>

<div class=”slide”>
<img src=”images/image1.jpg”>
</div>

<div class=”slide”>
<img src=”images/image1.jpg”>
</div>

<div class=”slide”>
<img src=”images/image1.jpg”>
</div>

</div>

Once your slider markup is in place we will replace the “.slide” child div’s with a block of PHP.

<?php
foreach(glob(‘./images/*.*’) as $filename){
echo “<img src='” . $filename . “‘ />”;
}
?>

If you have the images in another directory, let’s say “slider” inside of “images, you would just have the code look like this:

<?php
foreach(glob(‘./images/slider/*.*’) as $filename){
echo “<img src='” . $filename . “‘ />”;
}
?>

If your directory is set up properly your page should then pull in all of the images in that folder dynamically.

Read More
Share
proper noun logo blue

Proper Noun is an SEO, digital growth, and content marketing agency located in Fort Lauderdale, FL.

Twitter Facebook-f Google-plus-g Pinterest-p Linkedin-in

Contacts

Our Offices
300 SW 1st Ave #155
Fort Lauderdale, FL 33301
Give Us A Call
(954)674-1258

Our Services

  • Content Marketing
  • Ecommerce SEO Services
  • Enterprise Business SEO
  • Managed Outreach
  • Technical SEO
  • Website Optimization

Our Company

  • Blog
  • Contact Us
  • Book A Demo
  • Case Studies
  • Article Writing
  • Website Directory

© 2022 Proper Noun. All Rights Reserved.

Proper Noun is a content marketing agency located in Fort Lauderdale, FL. Proper Noun provides managed content marketing campaigns and managed outreach campaigns for ecommerce businesses, saas products, law firms, real estate, enterprise businesses and much more. We also offer a la carte content creation services.

Markets We Serve

  • Ecommerce SEO
  • Enterprise SEO
  • International SEO
  • National SEO
  • Local SEO
  • B2B SEO
  • Whitelabel SEO
  • SEO Consulting
  • SEO Reseller

Contacts



8 800 2563 123

  emil@yoursite.com

 27 Division St, New York, NY 10002, United States