300 of 410 menu

The ftell Function

The ftell function returns the current position of the pointer in a file stream. The position is specified in bytes from the beginning of the file. The function takes one parameter - a pointer to an open file resource.

Syntax

ftell(resource $handle): int|false

Example

Determine the current position in a newly opened file:

<?php $file = fopen('test.txt', 'r'); echo ftell($file); fclose($file); ?>

Code execution result:

0

Example

Determine the position after reading several bytes:

<?php $file = fopen('test.txt', 'r'); fread($file, 5); echo ftell($file); fclose($file); ?>

Code execution result:

5

Example

Check the position after moving the pointer:

<?php $file = fopen('test.txt', 'r'); fseek($file, 10); echo ftell($file); fclose($file); ?>

Code execution result:

10

See Also

  • the fseek function,
    which moves the file pointer
  • the rewind function,
    which resets the file pointer
  • the filesize function,
    which returns the file size
byenru