fileopen in PHP
In this article, we will discuss how to fileopen in PHP using the fopen() function. This function is used to open a file. It requires two arguments: first the file name and then the mode in which the file is to be opened.
fopen(string $filename, string $mode);
file name represents the file to be opened and $mode represents the file mode like read-only, read-write, write-only, etc.
<?php $handle = fopen("d:\\php\\file.txt", "r"); ?>
PHP opening modes:
- R – Opens the file in read-only mode.
- r+ – Opens the file in read-write mode.
- W – Opens the file in write-only mode.
- w+ – Opens file in read-write mode.
- A – Opens the file in write-only mode.
- a+ – Opens the file in read-write mode.
If an attempt to open a file fails then fopen returns a value of false otherwise it returns a file pointer which is used for further reading or writing to that file.