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

  • Home
  • SEARCH
  • 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 7590921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:31:32+00:00 2026-05-30T20:31:32+00:00

I have this dir structure for logs logs -2012 –01 —01.php —02.php –02 —20.php

  • 0

I have this dir structure for logs

logs
-2012
--01
---01.php
---02.php
--02
---20.php
---23.php

I want to be able to use PHP’s RecursiveTreeIterator to be able to display a tree having actual php files(not dirs) as links to display the file contents.

Using the first answer in this question as a guide: Sorting files per directory using SPL's DirectoryTreeIterator

I am new to most of PHP 5’s SPL so I need some help here. How do I build the tree? Thanks!

  • 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-05-30T20:31:33+00:00Added an answer on May 30, 2026 at 8:31 pm

    As an alternative to the links I provided in the comments already:

    • ASCII Library for Creating "Pretty" Directory Trees?
    • Multidimensional array iteration

    you can also extend the TreeIterator’s current() method to provide additional markup:

    class LinkedRecursiveTreeIterator extends RecursiveTreeIterator
    {
        public function current()
        {
            return str_replace(
                $this->getInnerIterator()->current(),
                sprintf(
                    '<a href="%1$s">%1$s</a>',
                    $this->getInnerIterator()->current()
                ),
                parent::current()
            );
        }
    }
    
    $treeIterator = new LinkedRecursiveTreeIterator(
        new RecursiveDirectoryIterator('/path/to/dir'),
        LinkedRecursiveTreeIterator::LEAVES_ONLY);
    
    foreach($treeIterator as $val) echo $val, PHP_EOL;
    

    The above will print the regular ASCII tree the TreeIterator prints but will wrap the filename into hyperlinks. Note that $this->getInnerIterator()->current() returns File objects, so you can access any other file properties, like filesize, last modified, etc, as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dir structure like the following: [me@mypc]$ tree . . ├── set01
I have a directory structure like this Root Sub Dir A Content Admin And
Let's say I have this dir structure: /project1 /SomeFolder /obj /bin /project2 /obj /bin
Say I have this url: http://site.example/dir/ In this folder I have these files: test.ascx.cs
I have this on line 56 in my environment.rb: I18n.load_path += Dir[ File.join(RAILS_ROOT, 'lib',
At the beginning of a makefile I have this line : PATH := $(PATH):/other/dir
I have this code in jQuery, that I want to reimplement with the prototype
I have a directory structure as follows dir----| | |--dir1\ some\ thing--result.pdf | |--dir2\
I have a data structure that looks like this: Model Place primary key id
I have a directory structure that looks like this: basedir/dir1/dir2/dir3/dir4/myzip/subdirs I would like to

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.