Search code examples
phpwebfile-read

filesize() expects parameter 1 to be a valid path - PHP


I am tryig to read an entire file in PHP, but I have this issue with filesize function. Here is the code:

<?php
 $file = fopen("file.txt", "r");
 echo $file;

 $fsize = filesize($file);
 //$ftext = fread($file, $fsize);
 //echo $ftext;
?>

Solution

  • The parameter should be the string of the path of the file, not the file itself.
    Try this: $fsize = filesize("file.txt");