php读取文件的三个方法

myglob(getcwd()."/*");

function mydir($dir){
    $d = dir($dir);
    while(($file = $d->read()) !== false){
        if($file != "." && $file != ".."){
            if(is_dir($dir.DIRECTORY_SEPARATOR.$file)){
                echo "目录:".$dir.DIRECTORY_SEPARATOR.$file."
"; mydir($dir.DIRECTORY_SEPARATOR.$file); } else { echo "文件:".$dir.DIRECTORY_SEPARATOR.$file."
"; } } } $d->close(); } function myreaddir($dir){ $hander = opendir($dir); // var_dump($hander);exit; if($hander){ while(($file = readdir($hander)) != false){ if($file != "." && $file != ".."){ if(is_dir($dir.DIRECTORY_SEPARATOR.$file)){ echo "目录:".$dir.DIRECTORY_SEPARATOR.$file."
"; myreaddir($dir.DIRECTORY_SEPARATOR.$file.DIRECTORY_SEPARATOR); } else { echo "文件:".$dir.$file."
"; } } } } closedir($hander); } function myglob($dir){ // print_r(g);exit; foreach(glob($dir) as $file){ if($file != "." && $file != ".."){ // echo $file."
"; if(is_dir($file)){ echo "目录:".$file."
"; myglob($file."/*"); } else { echo "文件:".$file."
"; } } } }

你可能感兴趣的:(php,开发语言)