WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0
Return the size of a file, or the number of unread bytes in a stream or socket
There are two different forms for this function.
Filename Form - The syntax is the same as in mainline PHP, and uses a filename for the parameter:
Handle Form - The syntax is unique to uPHP,1) and uses an open resource handle for the parameter (which works with streams, sockets, ports and files):
The Handle Form works in different ways, depending on the type of resource. For streams, sockets and ports it will return the number of unread bytes in the receive buffer. For files it will return the total number of bytes in the file.2)
$filename: Full path and filename (Filename Form)
$handle: Valid handle of a previously opened resource (Handle Form)
Integer number of bytes in the file, or pending in the stream or socket
<? $syslog="/logs/log.txt"; if (file_exists($syslog)) print("The System Log contains ".filesize($syslog)." bytes"); ?>
<? $f=fopen("/index.cgi","r"); if ($f) { print(filesize($f)); // output the file size fclose($f); } ?>
This example is extracted from the Wattmon OS “/scripts/ip_dongle.cgi”:
<? $dns_ip=ini_get("/config/dns.ini","dns","my.wattmon.com","my.wattmon.com"); $f=fsockopen($dns_ip,80,30); if ($f) { // ... code not shown: send a request to my.wattmon.com using fwrite() ... while (!filesize($f)) sleep(10); // wait until we begin to get a response $str=fread($f,filesize($f)); // retrieve all the bytes pending // ... code not shown: process the response in $str ... } ?>
findfirst() - Start searching the current folder for files matching a pattern and attributes ['filesize' is one of the array elements returned, see also findnext()]
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
fwrite() - Write data to a file, stream or socket
feof() - Test if no more data is available in a file, stream or socket [possibly useful if you don't need to know the exact number of bytes pending in a stream]
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
file_exists() - Check if a file exists
ini_get() - Get a value from an INI file