No text output

Part not executed:

echo @fread($file,filesize("$put"));
        fclose($file);

I can’t figure out why.


Answer 1, authority 100%

You are looping through the entire file with fgets. The read cursor is at the end of the file. Then fread will naturally throw an error, since the entire file has already been read. It is advisable to write like this:

<?
$put = $_POST['file'];
$file = fopen("$put","r");
$linesCnt = 0;
if(!$file)
  {
    echo("  ");
  }
    else
  {
    $num_str =  0; $strfile = "";
    while (!feof($file))
    {
        $strfile .= fgets($file);
        $num_str++;
    }
    echo " <br /> Kolvo strok ($num_str)";
    echo " <br /> soderzanie faila: <br />";
    echo $strfile;
    fclose($file);
}
?>

Answer 2, authority 50%

Precede this part with

rewind ($file); //  fseek($file, 0);

You are trying to read data when the pointer is at the end of the file.


Answer 3, authority 50%

if(!file)< is that a typo, I hope?

echo @fread($file,filesize("$put"));<- what nonsense.
You have already read the file. Make a “buffer” when reading, then just output it:

$buf = '';
while (!feof($file))
    {
        $buf .= fgets($file);
        $num_str++;
    }
    echo " <br /> Kolvo strok ($num_str)";
    echo " <br /> soderzanie faila: <br />";
    echo $buf;
    fclose($file);