The manual on "include" http://php.net/manual/en/function.include.php states:
"The include statement includes and evaluates the specified file.".
It makes no mention for folders.
Adding the /
at the end of "secure" include("../../secure/");
which would technically try and look for an index file, still won't work because PHP's include()
requires a specific filename.
However, if you want to include all files such as ones with an .html
extension, you can use:
foreach (glob("../../*.html") as $filename)
{
include $filename;
}
You could probably get away with something like this in order to include all files inside a given folder:
foreach (glob("../../folder/*") as $filename)
{
include $filename;
}
Or using scandir()
: and pulled from this answer on Stack https://stackoverflow.com/a/2692368/
foreach (scandir(dirname(__FILE__)) as $filename) {
$path = dirname(__FILE__) . '/' . $filename;
if (is_file($path)) {
require $path;
}
}
I don't know what the ultimate goal is for you to want and use include("../../secure");
if it's to include all files in that folder, or an index file.
References:
Having error reporting set on your system to catch and display should be throwing you something similar to:
Warning: include(/home/user/htdocs/folder): failed to open stream: No such file or directory in /home/user/htdocs/other_folder/file.php on line x
Footnotes:
You may also need to use a full system path.
I.e.:
/var/user/home/htdocs/folder/file.xxx
Testing with a folder/file in my root proved to be successful: (On a Linux box)
include("../../folder_in_root/index.html");
but not
include("../../folder_in_root");
nor
include("../../folder_in_root/");
You can also use and define a constant: (again, if you want to include the index file of that folder)
define("TEST", "../../folder_in_root/index.html");
include(TEST); // do not quote this
Note that define("TEST", "../../folder_in_root/");
will not work; it must be a filename.
Reference: