PHP include和require在ubuntu中不工作,即使在设置了include_path之后


PHP include and require not working in ubuntu even after setting the include_path

下面是phpinfo()

显示的包含路径
include_path    .:/usr/share/php:/usr/share/pear:/var/www/html/WebPHP

有一个页面在/var/www/html/WebPHP/frags目录,我想包括在我的index.php.

但是没有效果

我做错了什么?

编辑

    <?php
        set_include_path("/var/www/html/WebPHP/frags");
        ini_set('include_path', '/var/www/html/WebPHP/frags')
        include 'frags/GuestHeader.php';
        echo phpinfo();
    ?>

如果您只想包含一个特定的文件,您应该在您的index.php文件中添加:

require_once '/path/to/your/file.php'; 

但是,如果你真的想包含整个目录,你可以这样做:

set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/your/directory');

编辑:如果还是不行,你可以这样做:

foreach (glob("/your/directory/*.php") as $filename) {
    require_once $filename;
}