Skip to content

Opening and Closing Files

Files must be opened before reading or writing.

The fopen() function opens a file and returns a file handle.

$file = fopen("example.txt", "r");
fclose($file);
  • r – read only
  • w – write (overwrite)
  • a – append
  • r+ – read and write