Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8575939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:48:36+00:00 2026-06-11T19:48:36+00:00

I wanted to know how fread function moves the file pointer inside the file.

  • 0

I wanted to know how fread function moves the file pointer inside the file.

lets consider the following scenario:

<?php
$file=fopen(binary.txt,rb);
fread($file,0x594);
function(fread($file,0x1a8), ....); // some function w/ first argument as fread O/P
?>

brief overview of the code:

it will open a binary file in read only mode. I wanted to know if my understanding is correct or not:

  1. The first invocation of the fread function will move the file pointer to position 0x594.

Since the position of the first byte in the binary file is considered 0, and fread function is reading 0x594 bytes, so what will be the new position of file pointer?

0x593 or 0x594?

  1. The second fread function will start reading from the previous file pointer position. So, everytime, there is an invocation of fread function, the position of file pointer is preserved?

Which means, in a sequence of fread function invocations, each fread function starts reading bytes from the position of the file pointer set by the previous fread function?

in this case, it will start reading bytes from position, 0x594 to (0x594+0x1a8) or 0x73c ?

thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:48:37+00:00Added an answer on June 11, 2026 at 7:48 pm

    You can investigate this yourself, using ftell(). The current position of the file pointer is an inherent part of the file infrastructure, and PHP is simply riding on top of libc/glibc’s implementation of fopen/fread/etc…

    However, consider this:

    $fh = fopen('somefile.txt', 'r');
    

    the file pointer will now be a position zero, because no data has been read.

    $data = fread($fh, 500);
    

    file pointer will now be at position 500, because it’s read positions 0->499 (500 bytes) as part of the previous fread call.

    $data = fread($fh, 0); // makes no sense to read 0 bytes, but hey...
    

    still at position 500

    $data = fread($fh, 1); // now at 501
    $data = fread($fh, 2); // now at 503
    

    etc…

    Basically, use ftell() to check for yourself. ftell() is used to retrieve the CURRENT LOCATION of the filepointer, so you can use remember where you are. You can then use rewind(), fseek(), etc… to move the pointer all over, then jump right back to where you were without losing place:

    $old_loc = ftell($fh); // 503
    fseek($fh, 9999);
    fseek($fh, 20000); // jump around a bit
    fseek($fh, $old_loc); // back to 503, ready to resume reading where we left off.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to know which is faster from the following scenario: Three tables A,
I wanted to know about Data Type implementation in PHP so I need a
I wanted know How to rename a file in ftp server using java. I
Hi I wanted know the reasons of the following code void main() { class
I wanted to know the behavior of std::vector::reserve() in following situations: Suppose reserve(N) is
Just wanted to know which is the best way to read a file that
I wanted to know if parsing the INI file in the constructor is ok
I'm reading binary data from a file, specifically from a zip file. (To know
I wanted know how the kernel is providing memory for simple C program .
Wanted to know if there was a way one could query shelveset details from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.