Returns the current position of the file read/write pointer (original) (raw)
ftell
(PHP 4, PHP 5, PHP 7)
ftell — Returns the current position of the file read/write pointer
Description
ftell ( resource $handle
) : int
Parameters
handle
The file pointer must be valid, and must point to a file successfully opened by fopen() or popen().ftell() gives undefined results for append-only streams (opened with "a" flag).
Return Values
Returns the position of the file pointer referenced byhandle
as an integer; i.e., its offset into the file stream.
If an error occurs, returns FALSE
.
Note: Because PHP's integer type is signed and many platforms use 32bit integers, some filesystem functions may return unexpected results for files which are larger than 2GB.
Examples
Example #1 ftell() example
<?php// opens a file and read some data $fp = fopen("/etc/passwd", "r"); <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi><mo>=</mo><mi>f</mi><mi>g</mi><mi>e</mi><mi>t</mi><mi>s</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">data = fgets(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">a</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mord mathnormal">s</span><span class="mopen">(</span></span></span></span>fp, 12);// where are we ? echo ftell($fp); // 11fclose($fp);?>