2010-11-05 4 views
-1

Je souhaite afficher des images provenant de plusieurs répertoires.Afficher des images à partir de plusieurs répertoires

J'ai ce dossier principal (arrière-plans) et dans ce DIR j'ai 45 dossiers chaque dossier a entre 10-20 images.

Je souhaite afficher toutes les images des répertoires.

concernant Al3in

+3

Quelle est votre question? –

+0

Y aura-t-il des images dans ce répertoire de premier niveau 'backgrounds 'que vous ** ne voudrez pas afficher? –

Répondre

0

Essayez plutôt celui-ci:

<?php 
// Recursivly search through a directory and sub-directories for all 
// image files. The returned result will be an array will all matches 
// and their path (relative to the path sent in through the $dir argument) 
// 
// $dir  - Directory to search through 
// $filetypes - Array of file extensions to match 
// 
// Returns: Array() of files that match the $filetypes filter (or standard 
//   image file extensions by default). 
// 
function recursiveFileSearch($dir = '.', $filetypes = null) 
{ 
    if (!is_dir($dir)) 
    return Array(); 

    // create a regex filter so we only grab image files 
    if (is_null($filetypes)) 
    $filetypes = Array('jpg','jpeg','gif','png'); 
    $fileFilter = '/\.('.implode('|',$filetypes).')$/i'; 

    // build a results array 
    $images = Array(); 

    // open the directory and begin searching 
    if (($dHandle = opendir($dir)) !== false) 
    { 
    // iterate all files 
    while (($file = readdir($dHandle)) !== false) 
    { 
     // we don't want the . or .. directory aliases 
     if ($file == '.' || $file == '..') 
     continue; 

     // compile the path for reference 
     $path = $dir . DIRECTORY_SEPARATOR . $file; 

     // is it a directory? if so, append the results 
     if (is_dir($path)) 
     $results = array_merge($results, recursiveFileSearch($path,$filetypes)); 
     // must be a file, see if it matches our patter and add it if necessary 
     else if (is_file($path) && preg_match($fileFilter,$file)) 
     $results[] = str_replace(DIRECTORY_SEPARATOR,'/',$path); 
    } 

    // close the directory when we're through 
    closedir($dHandle); 
    } 

    // return the outcome 
    return $results; 
} 
?> 
<html><body><?php array_map(create_function('$i','echo "<img src=\"{$i}\" alt=\"{$i}\" /><br />";'),recursiveFileSearch('backgrounds')); ?></body></html> 
Questions connexes