User Tools

Site Tools


uphp:functions:ftell

This is an old revision of the document!


ftell

WMPRO, WMMINI FW >= 1.94 WMMEGA FW >= 2.0

Return the current position of a file read/write pointer

Description

int ftell ( int $handle )

Return the current file pointer position in an active previously opened file

Parameter

$handle: Valid handle of a previously opened file

Return Values

File pointer position (returns 0 for the beginning of a file)

Example

<pre><?
  $file="/ftell_example.txt"
  $fp=fopen($file,"w");
  if ($fp) {
    print("                  Beginning position: ".ftell($fp)."\r\n");
    fwrite($fp,"0123456789");
    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);
    unlink($file);
  } else {
    print("File open failed\r\n");
  }
?></pre>

The above example will ouput:

                  Beginning position: 0
Position after writing 10 characters: 10
    Position after moving pointer -2: 8
   The character at that position is: 8

See Also

fseek() - Position the file pointer in an open file

feof() - Test if no more data is available in a file or stream

filesize() - Return the size of a file, or the number of unread bytes in a stream

fopen() - Open a file for reading or writing

fread() - Return bytes from a file or stream

fwrite() - Write data to a file or stream

fclose() - Close a file, stream or socket

unlink() - Delete a file

uphp/functions/ftell.1491312515.txt.gz · Last modified: 2021/09/13 05:56 (external edit)