File: /home/cataracts.me.uk/public_html/image/view.php
<?
$sid=explode('image/',$_SERVER['REQUEST_URI']);
$sid=$sid[1];
$sid = str_replace('%20',' ',$sid);
class DB_Conf { //database setup for the whole script
public static $DB_Config = array(
'DbConfig' => array(
'Hostname' => 'localhost', //database ip
'Username' => 'image_data', //database user name
'Password' => 'follypress1', //database password
'Database' => 'image_data', //database name
)
);
}
class DB_connect{
public function connect_db(){
$cont = mysqli_init();
mysqli_options($cont,MYSQLI_OPT_CONNECT_TIMEOUT, 30);
mysqli_real_connect($cont,DB_Conf::$DB_Config['DbConfig']['Hostname'], DB_Conf::$DB_Config['DbConfig']['Username'], DB_Conf::$DB_Config['DbConfig']['Password'], DB_Conf::$DB_Config['DbConfig']['Database']);
#echo @mysqli_ping($cont) ? 'true' : 'false';
return $cont;
}
public function disconnect_db($cont){
mysqli_close($cont);
}
}
$cont=DB_connect::connect_db();
$query = mysqli_query($cont, "select photodata, phototype, size, visits from images where name='$sid'");
$result= mysqli_fetch_assoc($query);
if(!$result){
header( "HTTP/1.0 404 Not Found");
}
else{
$contenttype="Content-type: ".$result['phototype'];
header($contenttype);
header("Accept-Ranges: bytes");
header("Cache-Control: maxage=604800");
$size=$result['size'];
header('Content-Length: ' . $result['size']);
echo $result['photodata'];
$visits=$result['visits']+1;
$query = mysqli_query($cont, "select data from `usage` where `value`='download'");
$result= mysqli_fetch_assoc($query);
#echo $result['data'] .'<br>';
$download=$result['data']+$size;
#echo $download;
$query = mysqli_query($cont, "UPDATE `usage` SET `data`='$download' where `value`='download' ");
$query = mysqli_query($cont, "UPDATE `images` SET `visits`='$visits' where `name`='$sid' ");
}
DB_connect::disconnect_db($cont);
?>