CodesJava

Easy learning with example program codes

PHP Open File

PHP Open File

To open a file in PHP, fopen() function is used. In general, fopen() function accepts two parameters:

Filename:  This parameter specifies the name of the file to be opened.

Mode: This parameter specifies the mode in which the file should be opened.

Syntax:

resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )

OR

resource fopen ( string $filename , string $mode )

MODES of fopen function:

$modeMODEDESCRIPTION
rRead only modePointer starts from the beginning of the file.
wWrite only modeOverwrites the existing file or creates a new file if it doesn’t exist. Pointer starts from the beginning of the file.
aWrite only modeContinues writing in the existing file or creates a new file if it doesn’t exist. Pointer starts from the end of the file.
xWrite only modeCreates a new file if it doesn’t exist or returns FALSE if the file already exists. Pointer starts from the beginning of the file.
cWrite only modeCreates a new file if it doesn’t exist or does nothing if the file already exists. Pointer starts from the beginning of the file.
r+Read Write modePointer starts from the beginning of the file.
w+Read Write modeOverwrites the existing file or creates a new file if it doesn’t exist. Pointer starts from the beginning of the file.
a+Read Write modeContinues writing in the existing file or creates a new file if it doesn’t exist. Pointer starts from the end of the file.
x+Read Write modeCreates a new file if it doesn’t exist or returns FALSE if the file already exists. Pointer starts from the beginning of the file
c+Read Write modeCreates a new file if it doesn’t exist or does nothing if the file already exists. Pointer starts from the beginning of the file.

 

Please follow and like us:
error
Posted in PHP   








Copyright © 2019 CodesJava DMCA.com Protection Status