Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9212179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:27:49+00:00 2026-06-18T01:27:49+00:00

Using an answer from elsewhere on SO, I am working on a basic PHP

  • 0

Using an answer from elsewhere on SO, I am working on a basic PHP iterator to show images in nested DIRs.

My goal is to have PHP run through the DIRs and add an IMG tag with the SRC pointing to the files through which it iterates.

I am mostly there, but there are some extra characters showing up which prevent the image from displaying.

CODE (h2 and h3 are for readability while debugging, problem exists whether they are there or not):

// Create recursive dir iterator which skips dot folders
$dir = new RecursiveDirectoryIterator('./images/families/',
    FilesystemIterator::SKIP_DOTS);

// Flatten the recursive iterator, folders come before their files
$it  = new RecursiveIteratorIterator($dir,
    RecursiveIteratorIterator::CHILD_FIRST);

// Maximum depth is 1 level deeper than the base folder
$it->setMaxDepth(5);

// Basic loop displaying different messages based on file or folder
foreach ($it as $fileinfo) {
    if ($fileinfo->isDir()) {
        printf("<h2>Folder - %s\n</h2>", $fileinfo->getFilename());
    } elseif ($fileinfo->isFile()) {
        printf("<h3><img src=\"images/families/%s/%s></h3>", $it->getSubPath(), $fileinfo->getFilename());
    }
}

RESULT via view source in browser:

Folder - smith/40th
<img src="images/families/smith/40th/40th_1.jpg>
<img src="images/families/smith/40th/40th_11.jpg>

..etc


RESULT in browser window (on choosing “open image in new window”):

"The requested URL /images/families/smith/40th/40th_1.jpg><img src= was not found on this server.""

This is the URL in the address bar:
/images/families/smith/40th/40th_1.jpg%3E%3Cimg%20src=

So my code creating the img is adding extra characters / creating characters not read properly by the browser.

Is this an encoding issue? Thanks for reading.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:27:50+00:00Added an answer on June 18, 2026 at 1:27 am

    You just missed the closing quote in the src attribute, which is causing it to run onto the subsequent markup.

    printf("<h3><img src=\"images/families/%s/%s\"></h3>", $it->getSubPath(), $fileinfo->getFilename());
    //-----------------------------------------^^^^^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have registered javascript under portal_javascript using the answer 1 from How to Disable
I am using the accepted answer from this question . The relevant code is
Similar to my question about returning from inside a using statement (whose answer was
I am trying to integrated linkedIn using this question answer Posting LinkedIn message from
I have an open socket to a remote terminal. Using the answer to Force
A question I could not answer from the bazaar documentation. If I have a
Using the answer from previous Question? MYSQL SQL (self) join? Using views is unworkable.
Using the answer from Easy way of loading projects with rebar dependencies , dependencies
I am using the answer from How to restrict grep to search only the
I have looked within Stack Overflow and online elsewhere but can't find an answer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.