簡體   English   中英

如何包含目錄中的所有 php 文件?

[英]How to include all php files from a directory?

我正在嘗試從具有此類代碼的目錄中包含.php 文件。 但它不起作用。 誰能幫我? 謝謝你。

<?php
$dir = "/file/";
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while(($file = readdir($dh)) !== false) {
            if ($file != "." && $file != "..") {
               include "$file";
            }
        }
        closedir($dh);
    }
}
?>

使用$dir作為$file的前綴后,它可以正常工作。

<?php
$dir = "../file/";
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if ($file != "." && $file != "..") {
                include_once $dir . $file;
            }
        }
        closedir($dh);
    }
}
echo $a . "<br>" . $b;

?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM