PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
New here. Looks like a great place to get some answers. I won't be long winded.
I have a folder structure that has images in the respective folders. I have a script that recurses these folders fine and prints out a directory tree. My question is: How can I just pull out the thumbnail images (prefixed "thumb_") and print out the same tree with only the thumbnail image links.
The ultimate goal is to populate a xml file with the paths as an element. Actually to go further, how would I get it to just give me the path filenames and no folder output.
OK, one question at a time. Don't want to get too greedy. The latter is not that important right now. Thanks.
OK, I don't mean to sound ignorant, but where and how would I apply your code? I'm not well versed in PHP yet and would appreciate a bit more guidance. I can see how it would work, but I just don't know where to insert it and output it. Thanks for your response, kettle_drum!
create_tree("."); // show all files
create_tree(".", '/^thumb_/'); // guess what
function create_tree($file_dir, $filter = '') { // added second parameter
if ($handle = @opendir($file_dir))
{
$list = array();
while (false !== ($file = @readdir($handle))) {
if ($file != "." && $file != "..") {
if( !empty($filter) && !is_dir($file_dir . '/' . $file) ) // do not filter out directories
if( !preg_match($filter, $file) ) continue; // skip to the next file
$list[] = $file; // no need to use $i var
}
}
echo "<ul>";
foreach($list as $file) { // you can iterate through an array like this
if( is_dir($file_dir . '/' . $file) ) { // and you may have files
// without extensions as well
// as directories with
// extensions, hence your
// check was not reliable
echo "<li>" . $file . "/</li>\n";
create_tree($file_dir . "/" . $file, $filter);
} else
echo "<li><a href="" . $file_dir . "/" . $file . "">" . $file . "</a></li>\n";
}
echo "</ul>";
closedir($handle);
}
}
Last edited by Weirdan on Mon Nov 01, 2004 8:52 am, edited 1 time in total.
Weirdan, I thank you kindly for your reply, but this doesn't work. It's traversing through the folders and it's not filtering out the thumb_. It's only giving me the thumbs if it's in the same folder (Which helps me as well!).
What would I modify to have it traverse through all the folders?