Kevin Griffiths Kevin Griffiths - 1 month ago 12
PHP Question

Why can't I see my .txt file from this php script

I'm using this script to see the content of a .text file -


$file = fopen("Gin_List_Website.txt","r");

echo("ERROR:cant open file .. :(");
echo("opened the file .. :)");

$buff = fread ($file,filesize("Gin_List_Website.txt"));
print $buff;
echo $buff;

But all I see is this line

opened the file .. :)

What am I doing wrong?

Answer Source

First you need to change if(!file) with if(!$file).

Here is more simple code example:

    $file = fopen("Gin_list_Website.txt", "r") or die("Unable to open file!");
    echo fread($file,filesize("Gin_list_Website.txt"));