PHP包含文件夹中的文件

时间:2015-07-13 20:55:55

标签: php

我提前道歉,我用谷歌搜索了& stackoverflow' d,无法得到我需要的正确答案。

我有以下内容;

if ($radiobutton == "1"){

    require ("/test/_testpage1.php");

}

radiobutton 2也做同样的事情,但转而去testpage2.php。这两者都不起作用。但是,如果我移动/ test /文件夹中的testpage1.php,它在public_html中完全正常。

if ($radiobutton == "1"){

    require ("_testpage1.php");

}

上述工作正常,但有利于保持整洁和安全;我更容易管理我想把东西放在文件夹中。

请问有人支持我很明显遗失的事情吗?

2 个答案:

答案 0 :(得分:1)

if your html root is /var/www/html (for example) when you try to require('/test/somefile.php') are trying to open in /test/ folder not in /var/www/html/test/

you can try this code?

/* without "/" */
require ("test/_testpage1.php");

答案 1 :(得分:0)

I think it's more safe to use fullpath than relative path, maybe something like :

require 'FULLPATH.DS.testpage2.php'

We can debug it more easily rather than relative path