Skip to content

Instantly share code, notes, and snippets.

@jack2jm
Created December 15, 2020 11:20
Show Gist options
  • Save jack2jm/ae11a022cc30fcda98ae5e65bef2fcdd to your computer and use it in GitHub Desktop.
Save jack2jm/ae11a022cc30fcda98ae5e65bef2fcdd to your computer and use it in GitHub Desktop.
how to open, read, and close a file on the server.
Modes Description
r -> Open a file for read only. File pointer starts at the beginning of the file
w -> Open a file for write only. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file
a -> Open a file for write only. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist
x -> Creates a new file for write only. Returns FALSE and an error if file already exists
r+ -> Open a file for read/write. File pointer starts at the beginning of the file
w+ -> Open a file for read/write. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file
a+ -> Open a file for read/write. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist
x+ -> Creates a new file for read/write. Returns FALSE and an error if file already exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment