Wafa

wafa -  
mpmp93 Messages postés 2931 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

comment parcourir des fichiers dans le serveur avec php

1 réponse

  1. mpmp93 Messages postés 2931 Date d'inscription   Statut Membre Dernière intervention   1 343
     
    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