I have a php script on an Apache2 web-server (on Ubuntu). The script creates files. It works well with relative paths specified with `.’ but it does not see the parent directory.
header('X-Real-Path1: ' . realpath('..')); <-- empty string
header('X-Real-Path2: ' . realpath('.')); <-- returns the actual directory
header('X-Real-Path3: ' . realpath(__DIR__)); <-- returns the actual directory
header('X-Real-Path4: ' . realpath(__DIR__. '/../')); <-- empty string
The user which runs the script has full access to the directories. Why doesn’t the script see the directories?
The open_basedir
value is /var/www/www-root/data:.
3
Answers
The user under which the process runs may not have access to that directory.
From the manual page:
Your are casting the output to string, and boolean false casts as empty string:
first check the permissions, and for testing you can set it to 777 just for now.
sudo chmod 777 -R [dirname]
This code should work fine
You can just take the actual directory and cut the last folder, this actually works:
Example:
Actual directory: /home/jVufzc
RUN THE CODE
Output: /home/
If you don’t want the final slash do this:
ABSOLUTELY put them in two different lines, or it will trim all the directory