NYCPHP Meetup

NYPHP.org

[nycphp-talk] AddType application/x-httpd-php .gif .jpg .etc

Andrew Yochum andrew at plexpod.com
Tue Mar 29 17:04:40 EST 2005


On Tue, Mar 29, 2005 at 04:13:39PM -0500, Adam Fields wrote:
> On Tue, Mar 29, 2005 at 04:08:38PM -0500, Andrew Yochum wrote:
> > I thought I'd ping the list about this before I dive into this idea.
> > Has anyone ever tried to set the PHP module as a handler for images?
> > 
> > I have something like this in mind:
> > 	AddType application/x-httpd-php .gif
> > 	AddType application/x-httpd-php .jpg
> > 	AddType application/x-httpd-php .png
> > 
> > Did you have actual binaries behind the requests or scripts?  Google
> > turned up some of the latter, though nothing terribly interesting.  I'm
> > interested in the former - binaries.  Were you successful?  Any hiccups
> > or pointers?
> > 
> > Yeah, I'm probably crazy.
> 
> I've never done this with php, but we used to do it all the time in
> Vignette. You can use this technique to do some cookie get/set for
> custom images.

I did some of that in Vignette StoryServer waaay back, too.  IIRC they
went so far as to call them "chips".

> I see no reason why it wouldn't work with php, although I don't
> understand your question about binaries.

Well, basically I want to insert PHP before and after an image is served
with a prepend / postpend script.  I had output buffering in my mind
because I figured the script flow at some point would be turned to the
image itself and this is where I think some possible quirkiness may
arise.  I imagined something like this:

- prepend script runs
	- sets up session
	- checks auth
	- output might be sent and script execution stopped for some
	  reason
	- starts output buffering
- requested "script" runs (the image!)
- postpend script runs
	- grabs output buffer
	- modifies, replaces, etc the image
	- caches the result given context
	- sends image to the browser

I can see not actually having to do the output buffering by having the
execution always stop in the prepend.  If the image itself is to be used
in the output, you can grab it from REUQUEST_URI and read it off the
filesystem. Something like: 

- prepend script runs
	- sets up session
	- checks auth
	- generate output, might modify, replace, etc the image
	- caches the result given context
	- sends image to the browser
	- exit()
- requested "script" never runs (the image!)

This is probably the more sane approach to this.

The end-game is to insert some functionality in place of images without
moving them/replacing them in the docroot.

Andrew




More information about the talk mailing list