This is an old revision of the document!
WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0
Write data to a file, stream or socket
This function performs a binary-safe write of strings or bytes specified by integers to a previously opened resource1)
$handle: Valid handle of a previously opened resource
$data: The string, int or array data to be written in one of the following forms:
Integer number of bytes successfully written
0 if no bytes were written4)
-1 for socket errors (reset, connection broken)5)
<? $fh = fopen("/fwrite_test.txt","w"); if (!$fh) { print("File open failed"); } else { $result =fwrite($fh,"Line 1"); $result+=fwrite($fh,13); $result+=fwrite($fh,10); $result+=fwrite($fh,array(65,66,67,68,69,70,13,10,"Line 3",13,10)); print($result." bytes were written to the file"); fclose($fh); } ?>
The above example will display:
24 bytes were written to the file
And the above example will create the file /fwrite_test.txt containing:
Line 1 ABCDEF Line 3
fopen() - Open a file for reading or writing
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
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