The fopen () function is used to open a file in PHP.
The first parameter of this function contains the name of the file you want to open, and the second parameter sets which mode is used to open the file:
Copy Code code as follows:
<?php
$file =fopen ("Welcome.txt", "R");
?>
The file may be opened in the following modes:
R: Read-only. The pointer is positioned at the beginning of the file, if the file does not complain.
r+: Read/write. The pointer is positioned at the beginning of the file and the error occurs if the file is not saved.
W: Write only. Open and empty the contents of the file, and create a new file if the file does not exist.
w+: Read/write. Open and empty the contents of the file, and create a new file if the file does not exist.
A: Append. Open and position the pointer at the end of the file, or create a new file if the file does not exist.
A +: Read/append. Open and position the pointer at the end of the file, or create a new file if the file does not exist.
X: Write only. Create a new file. Returns FALSE if the file is present.
x+: Read/write. Create a new file. Returns FALSE and an error if the file already exists.