第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何通過php正確顯示目錄和子目錄中的所有文件

如何通過php正確顯示目錄和子目錄中的所有文件

PHP
元芳怎么了 2021-10-08 21:29:02
我有 4 個文件夾,我想檢查其中的圖像和 php 文件。這是結(jié)構(gòu)文件夾安排。該main_folder包含兩個子文件夾(second_folder和third_folder) ,而third_folder包含子文件夾(fourth_folder)等。目前使用下面的代碼,我只能訪問first_main_folder 中的所有文件。$files = glob('first_Main_folder/*.{jpg,png,gif,php}', GLOB_BRACE);foreach($files as $file) {echo "<br>$file<br>";}請問如何訪問剩余子文件夾(second_folder、third_folder、fourth_folder)中的文件等等謝謝first_Main_foldertest.pngdata.phpcheck.gif    second_folder    tony.jpg    mark.gif    action.php    third_folder    index.php    post.php    sender.php    han.gif        fourth_folder            catch.php            index2.php            redirect.php       and so on 
查看完整描述

2 回答

?
BIG陽

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個贊

下面的這個函數(shù)將主目錄和所有子目錄都掃描到最后。這個對我有用。謝謝。


function outputFiles1($path){

    // Check directory exists or not

    if(file_exists($path) && is_dir($path)){

        // Search the files in this directory

        $files = glob($path ."/*");

        if(count($files) > 0){

            // Loop through retuned array

            foreach($files as $file){

                if(is_file("$file")){

                    // Display only filename

                    echo basename($file) . filesize($file) . "<br>";

                } else if(is_dir("$file")){

                    // Recursively call the function if directories found

                    outputFiles1("$file");

                }

            }

        } else{

            echo "ERROR: No such file found in the directory.";

        }

    } else {

        echo "ERROR: The directory does not exist.";

    }

}


// Call the function

outputFiles1("C:/xampp/htdocs/first_main_folder");


查看完整回答
反對 回復(fù) 2021-10-08
?
qq_遁去的一_1

TA貢獻(xiàn)1725條經(jīng)驗(yàn) 獲得超8個贊

下面的例子取自這篇文章。


function rsearch($folder, $pattern='/.*/') {

    $dir = new RecursiveDirectoryIterator($folder);

    $ite = new RecursiveIteratorIterator($dir);


    $files = new RegexIterator($ite, $pattern, RegexIterator::GET_MATCH);

    $fileList = array();


    foreach($files as $file) {

        $fileList = array_merge($fileList, $file);

    }

    return $fileList;

}



$result = rsearch('./');

print_r($result);


查看完整回答
反對 回復(fù) 2021-10-08
  • 2 回答
  • 0 關(guān)注
  • 219 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號