paddymull Posted December 5, 2009 Share Posted December 5, 2009 Hi all, I am trying to use a php script, but there looks like there is a problem with the script, it is not working correctly, the php script should change the images hosted to one main image if the monthly bandwidth is excited (image bandwidth_exceeded.png). it also displays and image if the image is no longer available (image not_found.png) this works but the bandwidth one doesn't. it uses a .htaccess file to do this, using the RewriteRule, but like i said its not working correctly, I have been playing about with the to files involved to see if i can fix it but i cannot see the problem. the two files can be seen below, could people have a look at them and see if they can see what the problem is. The bandwidth.php file is uploaded to my main directory and the .htaccess file is located in the the image folder. the to images (not_found.png and bandwidth_exceeded.png) are also uploaded to the main director. here are the two files .htaccess RewriteEngine On Options +FollowSymlinks RewriteRule ([A-Za-z0-9_-]{1,})/([A-Za-z0-9_-]{1,})\.(jpg|gif|png)$ ../bandwidth.php?u=$1&i=$2.$3 bandwidth.php <?php /* script: bandwidth.php purpose: checks all image requests and either displays the image, or the bandwidth exceeded message. logs bandwidth usage for images viewed. copyright: copyright 2009 */ // include site configuration require_once(dirname(__FILE__).'/includes/config.inc.php'); // get the image to view by username and image name $u = preg_replace('/[^a-z0-9_-]/i', '', $ace->getstr('u', $_REQUEST)); $i = preg_replace('/[^a-z0-9_.-]/i', '',$ace->getstr('i', $_REQUEST)); $iname = $ace->config->image_folder.$u.'/'.$i; $dot = strpos($i, '.'); $ctype = 'image/pjpeg'; if( $dot != -1 ){ $type = substr($i, $dot+1); if( $type != 'jpg' ) $ctype = 'image/'.$type; } $sql = "SELECT u.bandwidth_exceeded, i.image_id FROM {pa_dbprefix}images i, {pa_dbprefix}users u "; $sql .="WHERE CONCAT(i.name, '.', i.type)='".addslashes($i)."' "; $sql .="AND u.username='".addslashes($u)."' AND i.user_id=u.user_id "; $res = $ace->query($sql, 'Get Image And user'); $img = mysql_fetch_object($res); header("Status: 200 Ok"); header("Content-Disposition: inline;"); header('Pragma:'); header('Cache-Control:'); if( $img && @file_exists($iname) ){ $ref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $isadmin = false; if( preg_match('/admin\//i', $ref) ){ if(strpos($ref, $ace->config->siteurl) !== false){ $isadmin = true; } } if( $img->bandwidth_exceeded && !$isadmin ){ // header("Content-Type: image/png"); readfile(dirname(__FILE__).'/bandwidth_exceeded.png'); }else{ $lastModified = filemtime($iname); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); header("Content-Type: $ctype"); header('Expires: ' . gmdate("D, d M Y H:i:s", time() + 3600 * 72) . " GMT"); ob_start(); @readfile($iname); ob_end_flush(); if( !$isadmin ){ $sql = "UPDATE images SET bandwidth=bandwidth+filesize WHERE image_id={$img->image_id} "; @mysql_query($sql); } } }else{ header("Content-Type: image/png"); @readfile(dirname(__FILE__).'/not_found.png'); } exit(); ?> Please could someone help me with this thanks from Patrick Link to comment https://forums.phpfreaks.com/topic/184119-help-with-bandwidth-php-script/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.