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

  • Home
  • SEARCH
  • 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 8814581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:09:45+00:00 2026-06-14T04:09:45+00:00

Just wondering if there is any difference with the two below code examples: $image

  • 0

Just wondering if there is any difference with the two below code examples:

$image = 'http://www.example.com/image.jpg'

$photo = file_get_contents($image);

ob_start();
header("Content-type: image/jpeg");
print($photo);
ob_end_flush(); 

or…

$image = 'http://www.example.com/image.jpg'

$photo = file_get_contents($image);

ob_start();
header("Content-type: image/jpeg");
readfile($photo);
ob_end_flush();
  • 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-14T04:09:47+00:00Added an answer on June 14, 2026 at 4:09 am

    readfile‘s parameter is a filename, not the content itself. Therefore, you’d call it like this:

    $image = 'http://www.example.com/image.jpg'
    ob_start();
    header("Content-type: image/jpeg");
    readfile($image);
    ob_end_flush();
    

    Since readfile reads and write chunks at a time, its memory consumption will be constant, whereas when you store the result of file_get_contents into $photo, you’ll need to have enough memory to store the image.

    In your case, the output buffering makes the file_get_contents variant demand twice as much memory as the image’s size. For a large image, readfile therefore halves the memory requirements. Note that your output buffering means that the download will be delayed. If you don’t need it for anything else, you will get better performance (both in actual speed and server memory requirements) if you simply disable it:

    $image = 'http://www.example.com/image.jpg'
    header("Content-type: image/jpeg");
    if (@readfile($image) === false) {
       // print error image
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just wondering if there is any difference between the two different new
Just wondering is there any way I can check whether the url links to
i just wondering is there any performance issue or anything thing wrong if that
Just wondering if there is any way to get the NS records in C#.
Just wondering if there are any pitfalls using .net as the extension for a
Just wondering if there is any benchmark software that I can download that will
Was just wondering if there are any built in functions in c++ OR c#
Was just wondering if there was any software out there to do this? The
Hey, I'm just wondering if there's any easy function to make text suitable to
I'm just wondering, is there any way to run Selenium tests on Android in

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.