English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP ftell() Function Usage and Example

PHP Filesystem Reference Manual

The ftell() function can return the current position in the opened file. It returns the current file pointer position on success, and false on failure.

Syntax

int ftell ( resource $handle )

This function can return the position of the file pointer referenced by the handle, which means its offset in the file stream.

Example1

<?php
   $file = fopen("/PhpProject/sample.txt, "r");
   //Print Current Position
   echo ftell($file);
   //Change Current Position
   fseek($file, "10");
   //Print Current Position Again
   echo "\n" . ftell($file);
   fclose($file);
?>

Output Result

0
10

Example2

<?php
   //Open File and Read Data
   $file = fopen("/PhpProject/sample.txt, "r");
   $data = fgets($file, 7);
   echo ftell($file); 
   fclose($file);
?>

Output Result

6

PHP Filesystem Reference Manual