steviez Posted August 27, 2008 Share Posted August 27, 2008 Hi, I am developing a new image hosting script for my site and would like to track the bandwidth each image uses, Is there a way to do this in PHP and if so can someone please point me in the right direction Thanks Link to comment https://forums.phpfreaks.com/topic/121586-solved-track-image-bandwidth/ Share on other sites More sharing options...
discomatt Posted August 27, 2008 Share Posted August 27, 2008 Assuming you're serving the file using a PHP script, simply make a filesize() call before you read/serve the image and store it wherever. Link to comment https://forums.phpfreaks.com/topic/121586-solved-track-image-bandwidth/#findComment-627165 Share on other sites More sharing options...
steviez Posted August 27, 2008 Author Share Posted August 27, 2008 How does that track bandwidth? Link to comment https://forums.phpfreaks.com/topic/121586-solved-track-image-bandwidth/#findComment-627174 Share on other sites More sharing options...
DarkWater Posted August 27, 2008 Share Posted August 27, 2008 You track the filesize before serving up the image, and store it, adding to a running total for that image. Link to comment https://forums.phpfreaks.com/topic/121586-solved-track-image-bandwidth/#findComment-627175 Share on other sites More sharing options...
steviez Posted August 27, 2008 Author Share Posted August 27, 2008 any demos on how to do this? Link to comment https://forums.phpfreaks.com/topic/121586-solved-track-image-bandwidth/#findComment-627204 Share on other sites More sharing options...
benphelps Posted August 28, 2008 Share Posted August 28, 2008 <?php $file = $_GET['image']; // no trailing "/" for the image directory $imagedir = '.'; $bandwidthused = filesize($imagedir.'/'.$file) or ; ?> This would work if the image is called from the URL like this "http://domain.com/load.php?image=sample.jpg" From there the $bandwidthused var. will store the bandwidth the image used in bytes. Link to comment https://forums.phpfreaks.com/topic/121586-solved-track-image-bandwidth/#findComment-627448 Share on other sites More sharing options...
Prismatic Posted August 28, 2008 Share Posted August 28, 2008 You can even use mod_rewrite to make your urls look like valid image URL's yet point to your script http://www.yoursite.com/images.php?name=bleh.jpg vs http://www.yoursite.com/images/bleh.jpg Link to comment https://forums.phpfreaks.com/topic/121586-solved-track-image-bandwidth/#findComment-627595 Share on other sites More sharing options...
steviez Posted August 28, 2008 Author Share Posted August 28, 2008 thanks for all your help guys, i have got it working now Link to comment https://forums.phpfreaks.com/topic/121586-solved-track-image-bandwidth/#findComment-627599 Share on other sites More sharing options...
DyslexicDog Posted August 28, 2008 Share Posted August 28, 2008 <?php $file = $_GET['image']; // no trailing "/" for the image directory $imagedir = '.'; $bandwidthused = filesize($imagedir.'/'.$file) or ; ?> This would work if the image is called from the URL like this "http://domain.com/load.php?image=sample.jpg" From there the $bandwidthused var. will store the bandwidth the image used in bytes. This would be a unsafe way to do this and shouldn't be used on a production site. Be sure to include some error handling and sanitize your incoming variables. Link to comment https://forums.phpfreaks.com/topic/121586-solved-track-image-bandwidth/#findComment-627757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.