======fopen======
WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0
Open a file for reading or writing
====Description====
int
fopen (
string
$filename,
string
$mode
)
Attempt to open a file (or special stream) for reading or writing, and return the file handle for future operations
====Parameters====
$filename: If a path is omitted, the current directory will be used to search for the file. Relative paths are supported. Two special file names will open specific streams instead:
* 'php:%%//%%stdin' - This will open a stream that will accept characters from a telnet console, allowing for interactive applications responding to keystrokes, when using mode 'r'
* 'php:%%//%%stdout' - This will send output characters to the standard output device, such as a telnet console, when using mode 'w'
$mode: The following strings are supported:
* 'r' - Open the file (or stream) in read-only mode
* 'w' - Open the file (or stream) in write mode, which will overwrite the file
* 'a' - Open the file in append mode for writing, which will open the file and move the pointer to the end of the file
====Return Values====
Integer: File handle, or 0 if the attempt to open the file or stream fails
The file handle may be used together with the other file functions that require a handle such as [[fgets()]], [[fwrite()]], [[fclose()]] and [[feof()]]
====Example====
$f=fopen("/index.cgi","r");
if ($f) {
print("File opened successfully");
fclose($f);
} else {
print("File open failed");
}
?>
====See Also====
[[fseropen()]] - Open the serial port at the specified baud rate with optional parameters
[[f485open()]] - Open the RS-485 port at the specified baud rate and parity
[[fsockopen()]] - Open an internet socket connection with optional timeout
[[fread()]] - Read bytes from a file, stream or socket
[[fgets()]] - Return a single line from a file, stream or socket, with optional size limit
[[fwrite()]] - Write data to a file, stream or socket
[[tar_put()]] - Add a file to an open file in TAR format
[[feof()]] - Test if no more data is available in a file, stream or socket
[[filesize()]] - Return the size of a file, or the number of unread bytes in a stream or socket
[[fseek()]] - Position the file pointer in an open file
[[ftell()]] - Return the current position of a file read/write pointer
[[fclose()]] - Close a file, stream or socket