I’m currently trying to develop a method to get a overview of all my different web templates I’ve created and (legally) downloaded over the years. I thought about displaying them like WordPress is previewing its templates with a small preview window, displaying the concrete file with styles and everything.
How do I divide them into rows and columns and create Ajax modal window open on preview and pagination and so on?
I believe I can manage, but it is the concept itself about iterating over several folders and then finding all index.htm
and index.html
pages and displaying them.
I’ve not worked very much with directories in PHP and the only references and code stumps I’ve found so far is just to list all the files in a certain directory like, what it contains.
Is there a script, a function, snippet or just some information to create such a (probably simple) preview function?
glob('*.html')
will work if they’re all in one directory.If you want to walk a file tree — checking everything in the current directory and in subdirectories and subdirectories of subdirectories (etc) — then you have a couple of options.
One would be to use the unix
find
command with one of the methods of PHP system invocation. Something like:find <search_root_dir> -name "*.html" -print
will get you output that looks something like
Another thing you could do is write a recursive function that uses
chdir
andreaddir
or maybescandir
, something like:Then, write another function:
And call it like this:
Or, write dir_walk so it accepts an object with a method call you can make inside. There’s some variations possible here.