wee493 Posted April 8, 2010 Share Posted April 8, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/197963-how-do-i-track-image-views/ Share on other sites More sharing options...
oni-kun Posted April 8, 2010 Share Posted April 8, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/197963-how-do-i-track-image-views/#findComment-1038775 Share on other sites More sharing options...
wee493 Posted April 8, 2010 Author Share Posted April 8, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/197963-how-do-i-track-image-views/#findComment-1038780 Share on other sites More sharing options...
wee493 Posted April 8, 2010 Author Share Posted April 8, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/197963-how-do-i-track-image-views/#findComment-1038791 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.