Friday, October 10, 2025
HomeLanguagesPHP | ftell( ) Function

PHP | ftell( ) Function

The ftell() function in PHP is an inbuilt function which is used to return the current position in an open file. The file is sent as a parameter to the ftell() function and it returns the current file pointer position on success, or FALSE on failure.
Syntax: 
 

ftell( $file )

Parameters Used: The ftell() function in PHP accepts only one parameter $file. It is a mandatory parameter which specifies the file.
Return Value: It returns the current file pointer position on success, or FALSE on failure.
Exceptions
 

  1. Some filesystem functions may return unexpected results for files which are larger than 2GB since PHP’s integer type is signed and many platforms use 32bit integers.
  2. When opening a file for reading and writing via fopen(‘file’, ‘a+’) the file pointer should be at the end of the file.

Examples: 
 

Input : $myfile = fopen("gfg.txt", "r");
        echo ftell($myfile);
Output : 0

Input : $myfile = fopen("gfg.txt", "r");
        echo ftell($myfile);
        fseek($myfile, "36");
        echo ftell($myfile);
Output : 0
         36

Below programs illustrate the ftell() function:
Program 1: In the below program the file named gfg.txt contains the following content. 
 

Geeksforneveropen is a portal for neveropen! 
 

 

php




<?php
// Opening a file in read. mode
$myfile = fopen("gfg.txt", "r");
 
// displaying the current position of the pointer in the opened file
echo ftell($myfile);
 
// closing the file
fclose($myfile);
?>


Output: 
 

0

Program 2: In the below program the file named gfg.txt contains the following content. 
 

Geeksforneveropen is a portal for neveropen! 
 

 

php




<?php
// Opening a file in read. mode
$myfile = fopen("gfg.txt", "r");
 
// displaying the current position of the pointer in the opened file
echo ftell($myfile);
 
// changing current position
fseek($myfile, "36");
 
//displaying current position
echo "<br />" . ftell($myfile);
 
// closing the file
fclose($myfile);
?>


Output: 
 

0
36

Reference: http://php.net/manual/en/function.ftell.php
 

RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7099 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS