Wafa

Fermé
wafa - 4 avril 2014 à 12:45
mpmp93 Messages postés 6652 Date d'inscription mercredi 13 avril 2011 Statut Membre Dernière intervention 28 septembre 2015 - 4 avril 2014 à 13:20
Bonjour,


comment parcourir des fichiers dans le serveur avec php

1 réponse

mpmp93 Messages postés 6652 Date d'inscription mercredi 13 avril 2011 Statut Membre Dernière intervention 28 septembre 2015 1 339
4 avril 2014 à 13:20
Bonjour,

Comme ceci?

function getsubdir($str,$dir) {
    // Remove the filename
    $str = dirname($str);

    // Remove the $dir
    if(!empty($dir)){
        $str = str_replace($dir,"",$str);
    }

    // Remove the leading '/' if there is one
    $si = stripos($str,"/");
    if($si == 0){
        $str = substr($str,1);
    }

    // Remove everything after the subdir (if there is anything)
    $lastpart = strchr($str,"/");
    $str = str_replace($lastpart,"",$str);

    return $str;
} 


et

$str = "dir1/dir2/dir3/dir4/filename.ext";
$dir = "dir1/dir2";

$subdir = getsubdir($str,$dir);
echo $subdir; // sort "dir3"
1