readfile in directory outside of public_html


I’m trying to read a file outside of the public_html folder.

$file = '/var/www/new.txt';

$fileHandle = file_get_contents($file);

    $o = mysqli_num_rows($result);
    if ($o)
        echo 'Error authenticating please contact support';
else {
    echo '';

I think the php file doesn’t have permissions to access this file, how would I be able to make it have access to this file?


try to access your file via relational path.

for example your folder structure is:


in your reader.php :

    $file = '../folder/new.txt';
    $fileHandle = file_get_contents($file);

Answered By – Milad Elyasi

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published