<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Images extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
	}

	public function blob() 
	{
		$image_name = $this->uri->segment(3);
		if($image_name)
		{
			$image = FALSE;
			if(substr($image_name,0,5)=='part_')
			{
				$participation = $this->db->query('Select image_string From participations Where image_name = ?',array($image_name))->row_array();
				if(sizeof($participation)>0)
				{	
					$image      = @imagecreatefromstring($participation['image_string']);
					$image_type = 'image/jpeg';
				}
			}
			else
			{
				$file = $this->db->query('Select file_blob,file_type From files Where file_name = ?',array($image_name))->row_array();
				if(sizeof($file)>0)
				{	
					$image      = @imagecreatefromstring($file['file_blob']);
					$image_type = $file['file_type'];
				}
			}
			if($image !== FALSE)
			{
				header('Expires:'.gmdate('D, d M Y H:i:s \G\M\T', strtotime('+1 months')));
				header('Content-type:'.$image_type);
				imagejpeg($image);
				imagedestroy($image);
			}
		}		
	}
}
/* End of file images.php */
/* Location: ./application/controllers/images.php */