On 8/30/06, Stut <[EMAIL PROTECTED]> wrote:
Peter Lauri wrote:
> I have some images stored in a database (only file name and other relevant
> information, rest stored in file system).
>
> I use the following html to access them:
>
> <img src='image.php?imageid=123' />
>
> At some pages I have the same image, so that tag will be seen on multiple
> places on the same page. So what I am curious is why all of the different
> images are loaded separately, instead of just recognizing that they are the
> same and use a cache version?
>
> This is the code that do all the work:
>
>   Header ("Content-type: $image_type");
>   readfile("files/$image");
>
> I am a little bit lost here; kick me in the right direction if you can :)
>

Probably because the browser sees the ? in the URL, thinks dynamic and
doesn't cache the result. You can set caching headers to get around this

You also have to remember that php by default sends the headers to
prevent caching, take a look at the headers responded via a static
.jpg file and a php page tha sends an image; You'll notice all those
extra no-cache type headers that enforce any browser to not reload a
(local) cached version of the file.

To get best performance
 support a HEAD request:
   send last-modified: and content-length: with the orignal sending
of the file and within your php script if the client requests a
IF_MODIFIED_SINCE header check the header against the value, if it
matches respond with something like:
  header('HTTP/1.0 304 Not modified');
  exit;

 support partial requests:
  check for the http header for partial content requests (I forget
the name, perhaps someone can remind me of it) and respond according
to the http specs.

HTH,
Curt.

(Google for it), or if you want *all* browsers to do it right, even the
poorly implemented ones, you could modify the URL so it doesn't have the
?. I do this using the Apache MultiViews option and a URL similar to
/image/123.gif. That actually runs /image.php which pulls the
REQUEST_URI server variable apart to get the required image. Do both and
you should be good for all browsers.

-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to