Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

ftell(3) [php man page]

FTELL(3)								 1								  FTELL(3)

ftell - Returns the current position of the file read/write pointer

SYNOPSIS
int ftell (resource $handle) DESCRIPTION
Returns the position of the file pointer referenced by $handle. PARAMETERS
o $handle - The file pointer must be valid, and must point to a file successfully opened by fopen(3) or popen(3). ftell(3) gives undefined results for append-only streams (opened with "a" flag). RETURN VALUES
Returns the position of the file pointer referenced by $handle 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(3) example <?php // opens a file and read some data $fp = fopen("/etc/passwd", "r"); $data = fgets($fp, 12); // where are we ? echo ftell($fp); // 11 fclose($fp); ?> SEE ALSO
fopen(3), popen(3), fseek(3), rewind(3). PHP Documentation Group FTELL(3)

Check Out this Related Man Page

FSEEK(3)								 1								  FSEEK(3)

fseek - Seeks on a file pointer

SYNOPSIS
int fseek (resource $handle, int $offset, [int $whence = SEEK_SET]) DESCRIPTION
Sets the file position indicator for the file referenced by $handle. The new position, measured in bytes from the beginning of the file, is obtained by adding $offset to the position specified by $whence. In general, it is allowed to seek past the end-of-file; if data is then written, reads in any unwritten region between the end-of-file and the sought position will yield bytes with value 0. However, certain streams may not support this behavior, especially when they have an underlying fixed size storage. PARAMETERS
o $handle -A file system pointer resource that is typically created using fopen(3). o $offset - The offset. To move to a position before the end-of-file, you need to pass a negative value in $offset and set $whence to SEEK_END. o $whence -$whence values are: o SEEK_SET - Set position equal to $offset bytes. o SEEK_CUR - Set position to current location plus $offset. o SEEK_END - Set position to end-of-file plus $offset. RETURN VALUES
Upon success, returns 0; otherwise, returns -1. EXAMPLES
Example #1 fseek(3) example <?php $fp = fopen('somefile.txt', 'r'); // read some data $data = fgets($fp, 4096); // move back to the beginning of the file // same as rewind($fp); fseek($fp, 0); ?> NOTES
Note If you have opened the file in append ( a or a+) mode, any data you write to the file will always be appended, regardless of the file position, and the result of calling fseek(3) will be undefined. Note Not all streams support seeking. For those that do not support seeking, forward seeking from the current position is accomplished by reading and discarding data; other forms of seeking will fail. SEE ALSO
ftell(3), rewind(3). PHP Documentation Group FSEEK(3)
Man Page

4 More Discussions You Might Find Interesting

1. Programming

Need help with ftell() function ..

Hello friends, I need help with ftell function in my programme, I can't figure out why I am not getting the file position what I supposed to get Here is my code void read_line(void *fh, double *input_re, double *input_im){ double a, b; char s; int n; ... (3 Replies)
Discussion started by: user_prady
3 Replies

2. Programming

fread: segementation fault(coredump) w/o stdlib.h

Hello All, I tried to test a sample fread example to read a complete file and the code is #include <stdio.h> #include <stdlib.h> int main () { FILE * pFile; long lSize; char * buffer; size_t result; pFile = fopen ( "test.xml" , "rb" ); if (pFile==NULL) {fputs ("File... (11 Replies)
Discussion started by: quintet
11 Replies

3. Shell Programming and Scripting

Mac. PHP fopen() does not create a file. Permissions.

5Thank you to those who responded. After a crazy amount of troubleshooting and getting hints and feedback from others, I was so darn determined to get on with my tutorials and I found the solution myself. Keyword search: php and 'Mac computer' and fopen and chmod. Using:php and Mac and... (1 Reply)
Discussion started by: iHaveAQuestion
1 Replies

4. Web Development

Mac. PHP. fopen( ) does not create a file. Permissions.

Thank you to those who responded. After a crazy amount of troubleshooting and getting hints and feedback from others, I was so darn determined to get on with my tutorials and I found the solution myself. Keyword search: php and 'Mac computer' and fopen and chmod. Using: php and Mac and... (2 Replies)
Discussion started by: iHaveAQuestion
2 Replies