Forum Moderators: coopster

Message Too Old, No Replies

running a php script on image call

         

topr8

6:26 pm on Jan 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i want to run a php script when a certain image is requested from my server, and then send the client an image.

...

the reason is that i want to do a database update if this image has been called by the client,
i realise i could get this from the server logs but i don't want to do it that way
- basically i want to check that the 'user' is requesting the image that is in the html page.

the first stage is relatively easy:
i enter a line in .htaccess that rewrites the image call to the .php page.

RewriteRule ^imagetest/1234\.jpg$ processimage.php?imageID=1234 [R]

(this is a rule for just one image, i would use a regular expression in the working case)

....

so the processimage.php page would do something like (pseudo code)...

1. get the imageID value
2. update the database to show that this image id was requested
3. send an image back to the client

it is this third step that i am stuck on ... how can i do this?

eelixduppy

6:34 pm on Jan 26, 2009 (gmt 0)



Step three should consist of grabbing the image on your server and echoing out the contents of it with the correct headers defined (header [php.net]).

For example:


# headers here
header("Content-Type: image/gif");
etc...
#
[url=http://www.php.net/readfile]readfile[/url]('/path/to/image.gif');

topr8

6:43 pm on Jan 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



great, thanks for your very prompt reply!

it was most helpful, as i'm trying to get this application finished today :)