Opening files

fopen() to open files or URL

 

$fileHandle = fopen( $filename, $mode ) ;

 

Creates a local file if it doesn't already exist

 

Returns a file pointer used for further reading/writing of the specified file, or FALSE upon failure to open the specified file

 

The file pointer indicates the location to read from or write to within the file.

Read or Write: file pointer at beginning

Append: file pointer at end

 

A filehandle is assigned to the specified filename:

 

File Opening Modes

r Read only. Pointer at beginning. Must exist
r+ Read & write. Pointer at beginning. Must exist
w Write only. Pointer at beginning. Truncate file to 0 length. Create if not exist
w+ Read & Write only. Pointer at beginning. Truncate file to 0 length. Create if not exist
a Write only. Pointer at end. Create if not exist
a+ Read & write. Pointer at end. Create if not exist
x Create and open for write only. Pointer at beginning. Fail if file already exists
x+ Create and open for read & write. Pointer at beginning. Fail if file already exists

 

File Mode Modifiers

t Translate to and from windows line endings: \n to or from \r\n
b Binary mode. Dont translate. Default

Leave a Reply