A
A
Alexander Globov2014-02-14 09:21:30
Yii
Alexander Globov, 2014-02-14 09:21:30

Weird require_once: doesn't work with including files in a directory above?

Hello.
Files located in the same directory are connected normally, as well as from subfolders. And the files located in the directory above "do not exist" for it. Initially, the problem appeared when trying to deploy Yii and put the framework code itself in the directory above.
I reproduced the problem with an example:
The file structure is as follows:
/var/www
-- file1.php
-- /test/
---- index.php
---- file2.php
The file /var/www/test/index.php looks like this So:

error_reporting(E_ALL);
echo getcwd();
echo "<br /><br />";
$path = dirname(__FILE__) . "/../file1.php";
$path2 = __DIR__ . "/../file1.php";
$path3 = "/var/www/file1.php";
echo  $path . "<br />";
echo  $path2 . "<br />";
echo  $path3 . "<br />";
echo "<br />";
var_dump(file_exists($path));
var_dump(file_exists($path2));
var_dump(file_exists($path3));
var_dump(file_exists("file2.php"));
#require_once (dirname(__FILE__).'/../file1.php');

Here is what the browser gives when opening /var/www/test/index.php
/var/www/test

/var/www/test/../file1.php
/var/www/test/../file1.php
/var/www/file1.php

bool(false) bool(false) bool(false) bool(true)

Maybe it's in the Apache settings and there is some kind of directive that governs this case?
OS Debian 7 Wheezy. Apache2 web server.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Push Pull, 2014-02-14
@sanekglobov

Check the open_basedir setting

M
Max, 2014-02-14
@AloneCoder

Use realpath(), Luke

F
FanatPHP, 2014-02-14
@FanatPHP

Where are the ERRORS, ERRORS? This is a site for programmers, not a shop at the entrance. And the visitors (as expected) are programmers, not fortune-tellers (however, judging by the previous answers, with programmers, after all, I strained). Especially for attendants - a brief introduction to programming: phpfaq.ru/debug#intro
If something does not work, then an error is generated. The error must be read and corrected.
We start looking for any Apache directives only AFTER we find out the reason. Not before, not instead, but AFTER. This is a very simple principle, it is not difficult to learn it at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question