I want to read file placed in the directory placed in root.
Let the file be at the place /root/folder/file.txt
This is my code:
I place this code in a file at /var/www/html/test.php that is my public html folder.
Now , when I open this file from my browser I get nothing on the screen ( that is because error reporting is off ) but when I open the same file placed in the same directory in CLI mode that is by ssh it gives me the correct output ( that is the array containing the contents of the file).
How to fix this ?
The root folder is (typically) for the root user with no read access to outside users. Therefore, your script that is being run by the apache user won’t be able to access it to read it.