2

Currently, my directory's structure looks like this:

- project
 - app
  - Config
   - file1.php
 - file.txt

This project folder is in /var/www/html folder. I am including file.txt in file1.php using the following code.

require_once '../../file.txt';

The Problem is, it can't find the file even when it is there. This is working on my local system which has Ubuntu 18.04, but not on the server that has Ubuntu 19.04. The project is built using the CakePHP framework.

$ ls -ld /var/www/html/project /var/www/html/project/app \
         /var/www/html/project/app/Config /var/www/html/project/file.txt
drwxr-xr-x  6 root root 4096 May 30 11:01 /var/www/html/project
drwxrwxr-x 13 root root 4096 May 29 08:09 /var/www/html/project/app
drwxrwxr-x  3 root root 4096 May 30 05:29 /var/www/html/project/app/Config
-rw-r--r--  1 root root 3401 May 30 11:13 /var/www/html/project/file.txt
3

It appears to me to be a difference in php's current working directory. The working system has .../project/app/Config as the current directory while the broken system has .../project as the current directory.

One workaround would be to determine the file1.php's current directory and then refer to file.txt with a relative path from there. If I use this in file1.php, it correctly includes file.txt:

require_once(dirname(__FILE__).'/../../file.txt');
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.