This shows you the differences between two versions of the page.
uphp:functions:filesize [2017/03/27 16:41] jeff |
uphp:functions:filesize [2021/09/13 05:57] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======filesize====== | ||
- | < | ||
- | |||
- | Return the size of a file, or the number of unread bytes in a stream | ||
- | |||
- | ====Description==== | ||
- | 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: | ||
- | |||
- | <well size=" | ||
- | <span style=" | ||
- | < | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | </ | ||
- | |||
- | **Handle Form** - The syntax is unique to uPHP,((The Handle Form is more commonly used on the Wattmon. Compared to mainline PHP, this uPHP form is a much simpler method for retrieving the number of bytes pending in a stream. For examples of how much more complex mainline PHP can be, take a look at the PHP function [[http:// | ||
- | |||
- | <well size=" | ||
- | <span style=" | ||
- | < | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | </ | ||
- | |||
- | 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.((I haven' | ||
- | |||
- | ====Parameters==== | ||
- | < | ||
- | |||
- | < | ||
- | |||
- | ====Return Value==== | ||
- | Bytes in the file or pending in the stream | ||
- | |||
- | ====Examples==== | ||
- | **Filename Form, output the size of the System Log:** | ||
- | |||
- | <code php> | ||
- | <? | ||
- | $syslog="/ | ||
- | if (file_exists($syslog)) print(" | ||
- | ?> | ||
- | </ | ||
- | |||
- | **Handle Form, for a file, output the file size:** | ||
- | |||
- | <code php> | ||
- | <? | ||
- | $f=fopen("/ | ||
- | if ($f) { | ||
- | print(filesize($f)); | ||
- | fclose($f); | ||
- | } | ||
- | ?></ | ||
- | |||
- | **Handle Form, for a socket** - this example is extracted from the Wattmon OS "/ | ||
- | |||
- | <code php> | ||
- | <? | ||
- | $dns_ip=ini_get("/ | ||
- | $f=fsockopen($dns_ip, | ||
- | 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, | ||
- | // ... code not shown: process the response in $str ... | ||
- | } | ||
- | ?> | ||
- | </ | ||
- | |||
- | |||
- | ====See Also==== | ||
- | [[feof()]] - Test if no more data is available in a file or stream [possibly useful if you don't need to know the exact number of bytes pending in a stream] | ||
- | |||
- | [[findfirst()]] - Start searching the current folder for files matching a pattern and attributes [' | ||
- | |||
- | [[fopen()]] - Open a file for reading or writing | ||
- | |||
- | [[f485open()]] - Open the RS-485 port at the specified baud rate and parity | ||
- | |||
- | [[fseropen()]] - Open the serial port at the specified baud rate with optional parameters | ||
- | |||
- | [[fsockopen()]] - Open an internet socket connection with optional timeout | ||
- | |||
- | [[fclose()]] - Close a file, stream or socket | ||
- | |||
- | [[file_exists()]] - Check if a file exists | ||
- | |||
- | [[ini_get()]] - Return the value associated with the key if it exists, or the default value otherwise | ||
- | |||
- | [[fread()]] - Return bytes from a file or stream | ||