0

The code always return 0 with the file with text on it

$filename = "the route";
    $handle = fopen($filename, "w");
    if (filesize($filename) == 0) {
      $txt = "{====views====}\n{====likes====}\n{====chapters====}\n{====comments====}";
      fwrite($handle, $txt);
      $contents = fread($handle, filesize($filename));
    } else {
      $contents = fread($handle, filesize($filename));
    }
    fclose($handle);
    echo $filename.": ".filesize($filename)." bytes";
    $views = explode("{====views====}", $contents);
    if (file_exists($filename)) {
      echo "<br>The file $filename exists";
    } else {
      echo "<br>The file $filename does not exist";
    }

outputs

the route: 0 Bytes

but the file has content on it. could someone help me?

Returns: Warning: fread(): Length parameter must be greater than 0 in E:\xampp\htdocs\host\host\storyedit.php on line 19

The file the route exists

rafael
  • 51
  • 1
  • 2
  • 6

0 Answers0