<?
include "mysqlcon.php";

if(isset($_GET['i'])) { $i = $_GET['i']; } else { $i = 0; }
if(isset($_GET['u'])) { $u = $_GET['u']; } else { $u = 0; }

$code = strrev(substr(strrev($u), 0, 5));
$u = strrev(substr(strrev($u), 5));

if(mysql_num_rows(mysql_query("SELECT * FROM ims WHERE u_id='$u' AND code='$code'")) != 1) { exit(); }

$image = mysql_num_rows(mysql_query("SELECT * FROM ims_image WHERE u_id='$u' AND i_id='$i'"));

if($i == 0 | $u == 0 | $image == 0) {
$filename = "./icons/notavail.gif";
$mime = "image/gif";
$image_name = "notavail.gif";

} else {
$image_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_image WHERE u_id='$u' AND i_id='$i'"));
$folder_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_folders WHERE u_id='$u' AND f_id='$image_info[f_id]'"));
$user_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims WHERE u_id='$u'"));
$filename = "./u/$u/$folder_info[f_id]/thumbs/$image_info[thumb]";
$image_name = $image_info[thumb];
  if($image_info[ext] == "jpeg" | $image_info[ext] == "jpg") {
  $mime = "image/jpeg";
  } elseif($image_info[ext] == "png") {
  $mime = "image/x-png";
  } elseif($image_info[ext] == "bmp") {
  $mime = "image/bmp";
  } elseif($image_info[ext] == "gif") {
  $mime = "image/gif";
  } elseif($image_info[ext] == "pdf") {
  $mime = "image/gif";
  $filename = "./icons/pdf.gif"; 
  }
}


$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);

header("Content-Type: $mime");
header("Content-Disposition: inline; filename=$image_name");
header("Pragma: no-cache");
header("Expires: 0");


echo $contents;

?>