User Tools

Site Tools


uphp:functions:filesize

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

uphp:functions:filesize [2017/03/27 16:41]
jeff
uphp:functions:filesize [2021/09/13 05:57]
Line 1: Line 1:
-======filesize====== 
-<badge>WMPRO, WMMINI FW >= 1.0</badge> <badge>WMMEGA FW >= 2.0</badge> 
- 
-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="sm"><html><span style="font-size:125%;color:green;">int 
-<span style="color:black;"></html>[[filesize]] 
-<html>( 
-<span style="color:green;">string 
-<span style="color:blue;">$filename 
-<span style="color:black;">) 
-</html></well> 
- 
-**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://php.net/manual/en/function.stream-get-meta-data.php|stream-get-meta-data]] which returns an array with one of the elements containing 'unread_bytes'.)) and uses an open resource handle for the parameter (which works with streams, sockets, ports and files): 
- 
-<well size="sm"><html><span style="font-size:125%;color:green;">int 
-<span style="color:black;"></html>[[filesize]] 
-<html>( 
-<span style="color:green;">int 
-<span style="color:blue;">$handle 
-<span style="color:black;">) 
-</html></well> 
- 
-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't verified this yet, perhaps for files the Handle Form returns the number of bytes remaining to be read beyond the pointer. - Jeff, 2/23/17)) 
- 
-====Parameters==== 
-<html><span style="color:blue;"><b>filename</b><span style="color:black;"></html>:  Full path and filename (Filename Form) 
- 
-<html><span style="color:blue;"><b>handle</b><span style="color:black;"></html>:  Valid handle of a previously opened resource (Handle Form) 
- 
-====Return Value==== 
-Bytes in the file or pending in the stream 
- 
-====Examples==== 
-**Filename Form, output the size of the System Log:** 
- 
-<code php> 
-<? 
-  $syslog="/logs/log.txt"; 
-  if (file_exists($syslog)) print("The System Log contains ".filesize($syslog)." bytes"); 
-?> 
-</code> 
- 
-**Handle Form, for a file, output the file size:** 
- 
-<code php> 
-<? 
-  $f=fopen("/index.cgi","r"); 
-  if ($f) { 
-    print(filesize($f)); // output the file size 
-    fclose($f); 
-  } 
-?></code> 
- 
-**Handle Form, for a socket** - this example is extracted from the Wattmon OS "/scripts/ip_dongle.cgi": 
- 
-<code php> 
-<? 
-  $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 ... 
-  } 
-?> 
-</code> 
- 
- 
-====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 ['filesize' is one of the array elements returned, see also [[findnext()]]] 
- 
-[[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 
  
uphp/functions/filesize.txt · Last modified: 2021/09/13 05:57 (external edit)