headers for images

images php coding issues or problems here.

Moderators: macek, egami, gesf

DoppyNL

headers for images

Postby DoppyNL » Sat Aug 17, 2002 11:11 pm

I store images in my database, and the return them to to browser using "image.php?id=234" this works fine except for some small problems:

1. When the user wants to save the file, he doesn't get the original filename of the image, how do I send the original filename with the image?

2. I noticed that caching of the images is not really working right now. Probably because the browser thinks that it is an dynamic file, wich can change. But I know for 100% certain that "image.php?id=234" will ALLWAYS be that image.
How do I tell the browser (and proxy's on the way) they can cache the file as long as they want??

I'm currently using the following headers:

Code: Select all

Header("Cache-Control: public");
Header('Content-type: ' . $image['imagetype']);

where $image['imagetype'] is fetched from the database ofcourse.

Greetz Daan

DoppyNL

Postby DoppyNL » Mon Aug 19, 2002 6:29 am

from a newsgroup:

to send the filename with the image:

Code: Select all

header("Content-disposition: inline; filename=mypic.png");

additionally, you can send the image size with the image:

Code: Select all

header("Content-lenght: ".filesize("mypic.png"));


Now I still have to find out how to cache the files...

Greetz Daan

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Postby WiZARD » Mon Aug 19, 2002 6:44 am

dvdbinternet wrote:from a newsgroup:

to send the filename with the image:

Code: Select all

header("Content-disposition: inline; filename=mypic.png");

additionally, you can send the image size with the image:

Code: Select all

header("Content-lenght: ".filesize("mypic.png"));


Now I still have to find out how to cache the files...

Greetz Daan

Hi!
Try set PRAGMA variable in HTML or set lifetime of session.

DoppyNL

Postby DoppyNL » Mon Aug 19, 2002 6:48 am

the PRAGMA variable is (if i'm correct) a html option, I want images to be cached as long as possible by the browser and proxys between the browser and the server.
These images are retrieved from a database using a php-script.

The lifetime of a session has nothing to do with this as far as I know, that is only about when the session can be safely destroyed (because the user isn't there anymore)

Greetz Daan

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Postby WiZARD » Mon Aug 19, 2002 6:55 am

dvdbinternet wrote:the PRAGMA variable is (if i'm correct) a html option, I want images to be cached as long as possible by the browser and proxys between the browser and the server.
These images are retrieved from a database using a php-script.

The lifetime of a session has nothing to do with this as far as I know, that is only about when the session can be safely destroyed (because the user isn't there anymore)

Greetz Daan

Why you insert in DB Images?
I hear about simply and faster method store images at server: PHP and MySQL Web Development -- by Luke Welling, Laura Thomson

DoppyNL

Postby DoppyNL » Mon Aug 19, 2002 7:02 am

because its much more easy to manage those images inside my site.
also, some images are not to be seen by some images, this way I can prevent that some users can see that images, because I can check that in the image-script.

OK, it can be done with the acces control of apache and stuff like that, but I simply prefer this solution, because it fits better in my way of programming and "security control"

Greetz Daan


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest