Lister dossier

albanimal Messages postés 1 Date d'inscription jeudi 12 août 2004 Statut Membre Dernière intervention 22 novembre 2007 - 22 nov. 2007 à 14:43
neigedhiver Messages postés 2480 Date d'inscription jeudi 30 novembre 2006 Statut Membre Dernière intervention 14 janvier 2011 - 22 nov. 2007 à 18:14
Bonjour dans un répertoire je vais chercher des images pour les
afficher sur une page, j'aimerai ne pas afficher les images commencant
par "mini_" est-ce que c'est possible, je n'arrive pas à trouver d'exemples ?

Merci !

4 réponses

cs_putch Messages postés 624 Date d'inscription mardi 6 mai 2003 Statut Membre Dernière intervention 14 décembre 2009 1
22 nov. 2007 à 15:49
salut !

pour parcourir un répertoire :
opendir() et
readdir() cf : http://fr.php.net/manual/fr/function.opendir.php


pour tester la sous-chaine "mini_" dans une autre : ereg("^mini_", $maChaine) cf : http://fr.php.net/manual/fr/function.ereg.php

++
0
neigedhiver Messages postés 2480 Date d'inscription jeudi 30 novembre 2006 Statut Membre Dernière intervention 14 janvier 2011 19
22 nov. 2007 à 16:15
Salut,

En PHP5 pour faire ça proprement :

class DirectoryFilterMini {
function __construct($sPath)
{
parent::__construct(new DirectoryIterator($sPath));
}

function accept()
{
if ($this -> isDir() && !$this -> isDot()) {
return (bool) preg_match('`^mini_`', $this -> getFilename());
}
else {
return false;
}
}
function key()
{
return $this->getInnerIterator()->getPath();
}
}

Et pour afficher les fichiers qui commencent par "mini_" dans un répertoire :

$oRep = new DirectopryFilterMini($sRepertoire);
foreach ($oRep as $fichier) {
echo $fichier;
}
0
winwarrior Messages postés 654 Date d'inscription jeudi 3 avril 2003 Statut Membre Dernière intervention 10 février 2009 1
22 nov. 2007 à 17:59
Sinon pour lister les fichiers :
chdir('repertoire');
$fichiers = glob('*');
print_r($fichiers)

win
0
neigedhiver Messages postés 2480 Date d'inscription jeudi 30 novembre 2006 Statut Membre Dernière intervention 14 janvier 2011 19
22 nov. 2007 à 18:14
Sauf que glob, niveau performances...
http://fr3.php.net/manual/fr/function.glob.php#62590
0
Rejoignez-nous