Jump to content

How do I track image views?


wee493

Recommended Posts

I have a url shortner/image host. I currently have all image views/embeds linking to mysite.com/image and and the htaccess rewrites to a php file that gets the requested image and had the following php

header("Cache-Control: public");
    header("Content-Type: image");
    header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($img_chk));


// Read file
readfile($img);

The real images are in the /files directory, not /images. I do this because I track the image views for the users. I don't mind users knowing the actual url to the file, it's just that if they visit it that way their view wont be tracked, if any of this makes since...

 

Well anyways, I was wondering if there is any other way to do this. I know this is not the most efficent way as my server had to load the file into php every time then read it instead of just having apache send the image to the user. I thought about switching to amazon s3, but I figured then I would still need to the the readfile() function for the users to see the file without having the actual link to the file.

 

Any ideas, or do I need to explain it some other way? In a very short summary, how do I count image views quickly/easily using php?

Link to comment
Share on other sites

How do you not know how to accomplish this? Create a column on each file row, and add views + 1. It doesn't matter what you do on that page, as long as you are outputting only image data. Just don't print anything relating to the query.

Link to comment
Share on other sites

How do you not know how to accomplish this? Create a column on each file row, and add views + 1. It doesn't matter what you do on that page, as long as you are outputting only image data. Just don't print anything relating to the query.

I know that. I already have this completely setup. If you would have read my post and not just the title you would know that.

 

I'm asking if there is another easier way as readfile($img); is sometimes slow on my vps and It seems a lot more time consuming than just loading the image.

 

If you visit http://adrianstech.com you will see the header image is hosted on my image hosting site and it can take a while to load sometimes. 

Link to comment
Share on other sites

I'm currently trying this way and it seems to be working better/faster.

 

	$chunk=20480; // bytes

	$sent=0;
	$fp=fopen($img, 'rb');
	do{
		$buffer = fread($fp,$chunk);
		$sent += strlen($buffer);
		print $buffer;flush();
	}
	while(!feof($fp)&&!connection_aborted());
	fclose($fp);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.