RE: [PHP] keeping track of external image linking with php?
| From: | Don Read | Date: | Tue, 24 Jul 2001 05:59:41 +0000 |
| Subject: | RE: [PHP] keeping track of external image linking with php? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-59300@lists.php.net to get a copy of this message | ||
On 23-Jul-2001 Matt Greer wrote:
> I don't think that's the best subject, but I'm not really sure how to phrase
> it.
>
> I'm not familiar with php's image capabilities. I've read about them a bit,
> but never really used them.
>
> I'd like to have an image that when accessed would cause php to kick in and
> do a few things before sending the image along to whoever is requesting it.
> Basically I'd like to keep a running tally of how many times a website is
> accessing an image on my server. Which functionally speaking is identical to
> a hit counter I guess.
>
> Is it possible to have on a webpage something like <img
> src="image.php?website=awebsite.com">
>
> and then image.php takes note of the website variable, does a few things
> with mysql, then passes on the image that is wanted, utilizing something
> from the gd library?
>
Sure,
/php/fetchimg.php?img=da_image.jpeg
/php/fetchimg.php
---
<?php
$ftype = strtolower(strrchr($img, '.'));
$types = array(
'.gif' => 'image/gif',
'.jpg' => 'image/jpeg',
'.mov' => 'video/quicktime',
'.mpe' => 'video/mpeg',
'.mpeg' => 'video/mpeg',
'.mpg' => 'video/mpeg'
);
$fname = "$DOCUMENT_ROOT/images/$img";
Header("Content-type: " .$types[$ftype]);
Header("Content-length: " .filesize($fname));
@readfile($fname);
$qry ="insert into foo (da_time,da_name) values (NOW(), '$img');
@mysql_query($qry);
?>
Regards,
--
Don Read dread@texas.net
-- It's always darkest before the dawn. So if you are going to
steal the neighbor's newspaper, that's the time to do it.