User Tools

Site Tools


uphp:functions:ftell

Differences

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

Link to this comparison view

Next revision
Previous revision
uphp:functions:ftell [2017/03/31 13:43]
jeff created
uphp:functions:ftell [2021/09/13 05:57] (current)
Line 1: Line 1:
 ======ftell====== ======ftell======
  
-<badge>WMPRO, WMMINI FW >= 1.0</badge> <badge>WMMEGA FW >= 2.0</badge>+<badge>WMPRO, WMMINI FW >= 1.94</badge> <badge>WMMEGA FW >= 2.0</badge>
  
-Position the file pointer in an open file+Return the current position of a file read/write pointer
  
 ====Description==== ====Description====
  
-<well size="sm"><html><span style="font-size:125%;color:green"></html>[[ftell]] +<well size="sm"><html> 
-<html>(+<span style="font-size:125%;color:green">int 
 +<span style="color:black">ftell (
 <span style="color:green">int <span style="color:green">int
-<span style="color:blue">$handle<span style="color:black">, +<span style="color:blue">$handle
-<span style="color:green">int +
-<span style="color:blue">$offset<span style="color:black">, +
-<span style="color:green">int +
-<span style="color:blue">$whence+
 <span style="color:black">) <span style="color:black">)
 </html></well> </html></well>
  
-This function will relocate the file pointer within an active file.  Three different start position options are available.+Return the current file pointer position in an active previously opened file
  
-====Parameters====+====Parameter====
  
-<html><span style="color:blue"><b>$handle</b><span style="color:black"></html>:  Valid handle of a previously opened resource +<html><b><span style="color:blue">$handle<span style="color:black"></b></html>:  Valid handle of a previously opened file
- +
-<html><span style="color:blue"><b>$offset</b><span style="color:black"></html>:  How far to move the pointer (bytes) +
- +
-<html><span style="color:blue"><b>$whence</b><span style="color:black"></html>:  Seek type, starting position option, from where to move the pointer: +
- +
-  * **0** - Seek from the **start of the file** +
-  * **1** - Seek from the **current position** +
-  * **2** - Seek from the **end of the file** (in reverse)+
  
 ====Return Values==== ====Return Values====
  
-None+<html><b><span style="color:green">Integer<span style="color:black"></b></html> file pointer position (returns 0 for the beginning of a file)
  
 ====Example==== ====Example====
  
 <code php> <code php>
-<? +<pre><? 
-  $fp=fopen("/index.cgi","r");+  $file="/ftell_example.txt" 
 +  $fp=fopen($file,"w");
   if ($fp) {   if ($fp) {
-    fseek($fp,10,2); // position to 10 characters before the end of the file +    print("                  Beginning position: ".ftell($fp)."\r\n"); 
-    $data=fread($fp,10); +    fwrite($fp,"0123456789"); 
-    print($data);+    print("Position after writing 10 characters: ".ftell($fp)."\r\n"); 
 +    fseek($fp,-2,1); 
 +    print("    Position after moving pointer -2: ".ftell($fp)."\r\n"); 
 +    print("   The character at that position is: ".fread($fp,1)."\r\n");
     fclose($fp);     fclose($fp);
 +    unlink($file);
   } else {   } else {
-    print("File open failed\n");+    print("File open failed\r\n");
   }   }
-?>+?></pre></code> 
 + 
 +The above example will ouput: 
 + 
 +<code> 
 +                  Beginning position: 0 
 +Position after writing 10 characters: 10 
 +    Position after moving pointer -2: 8 
 +   The character at that position is: 8
 </code> </code>
  
Line 56: Line 58:
 [[fopen()]] - Open a file for reading or writing [[fopen()]] - Open a file for reading or writing
  
-[[fread()]] - Return bytes from a file or stream+[[fseropen()]] - Open the serial port at the specified baud rate with optional parameters
  
-[[fgets()]] - Return a single line from a file or stream, with optional size limit +[[f485open()]] - Open the RS-485 port at the specified baud rate and parity
  
-[[fwrite()]] - Write data to a file or stream+[[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 
 + 
 +[[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
  
 [[fclose()]] - Close a file, stream or socket [[fclose()]] - Close a file, stream or socket
 +
 +[[unlink()]] - Remove a file (delete it)
  
uphp/functions/ftell.1490967808.txt.gz · Last modified: 2021/09/13 05:56 (external edit)