1

I'm using php to output an image using readfile function. I've set the headers for this php file as below:

$expires = 60*60*7;
header('Pragma: public');
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + $expires));
header('Content-Type: image/jpeg');
header("Cache-Control: maxage=".$expires);

Both expire and Cache-Control headers are set, but each time i load the url, image gets downloaded. Is there any other header rule needed to enable caching?

1 Answer 1

1

Use the Content Disposition header:

header("Content-Disposition: inline;filename=something.jpg")

This tells the browser to display it inline (rather than the default attchment, which triggers the download). Attachments will download regardless of cache values.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.