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 -

<?php

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

if(!file)
{
echo("ERROR:cant open file .. :(");
}
else
{
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:

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