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 524383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:33:44+00:00 2026-05-13T08:33:44+00:00

I am currently using the script below to output the contents of a JPEG

  • 0

I am currently using the script below to output the contents of a JPEG straight from a file. The reason I’m doing so is because I’m using mod_rewrite/php to mask the name of the original file. This is working partially as expected, except that Safari insists on downloading the photo instead of just allowing me to see it in the browser. Am I missing a header? Also, what modifications could I make to improve performance?

    error_reporting(0);

    // Find which image we're trying to get
    $_GET['id'];

    // In the real script, I do some proccessing here
    $filename = $_GET['id'] . '.jpg';

    // Getting headers sent by the client.
    $headers = apache_request_headers(); 

    // Checking if the client is validating his cache and if it is current.
    if (isset($headers['If-Modified-Since']) && (strtotime($headers['If-Modified-Since']) == filemtime($filename))) {

        // Client's cache IS current, so we just respond '304 Not Modified'.
        header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($filename)).' GMT', true, 304);

    } else {

        // Image not cached or cache outdated, we respond '200 OK' and output the image.
        header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($filename)).' GMT', true, 200);
        header('Content-Length: '.filesize($filename));
        header('Content-Type: image/jpeg');
        print file_get_contents($filename);

    }

?>

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-05-13T08:33:45+00:00Added an answer on May 13, 2026 at 8:33 am

    I can’t say why Safari is treating your images as attachments/downloads. I actually tested it in the latest Safari 4 on SL and it works OK. You could try sniffing the HTTP conversation and make sure no extra headers (e.g. content-disposition) are creeping in. Also it may pay to check over Safari config settings, maybe something subtle is different there to your other browsers?

    On the topic of performance:

    First I would try to eliminate the PHP altogether. See if you can leverage your webserver’s modules/configuration to achieve your goal.

    If you can’t do without the PHP, then you could try letting the webserver handle the actual delivery. You can do this in nginx with X-Accel-Redirect and in lighttpd and apache with X-Sendfile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using the script below to change an image on rollover. There are
I'm currently using php to populate a form with selections from a database. The
I'm currently using the below script which I found online: ######################################### #### BEGIN EDIT
I am currently using the following script to set this value as a String:
I am currently using Net::HTTP in a Ruby script to post files to a
I'm currently using the toprettyxml() function of the xml.dom module in a Python script
I currently have a Perl CGI script that parses incoming XML requests using XML::Simple
I found a nice script to import xml using powershell http://slash4.de/tutorials/Automatic_mediawiki_page_import_powershell_script Currently I don't
I am currently developing a very simple script in AutoHotKey, but it involves using
I have a CSV export script (enrdata_arch.php) which calls information from an existing database

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.