12-29-2011, 09:28 PM
[eluser]Unknown[/eluser]
To display an image stored in MySQL database I am using the following code in my controller
which is not working, all that I am getting is a string as output as below
but at the same time if I use this function in a simple php file and directly call the function in that file it works and outputs the image as desired.
I have also tried using
without any luck.
Any help here would be of much appreciation.
Thanks and happy new year.
To display an image stored in MySQL database I am using the following code in my controller
Code:
function display_image($id){
$user='root'; $password='Passw0rd'; $db='pppmis';
mysql_connect('localhost', $user, $password) or die('I cannot connect to db: ' .
mysql_error());
mysql_select_db('pppmis');
$query = mysql_query("SELECT * FROM project_image WHERE projectid = ".$id);
$row = mysql_fetch_array($query);
$content = $row['image'];
header("Content-type: ".$row['mime']);
echo $content;
}
which is not working, all that I am getting is a string as output as below
Quote:http://localhost/application/index.php/manage_project/display_image/1
but at the same time if I use this function in a simple php file and directly call the function in that file it works and outputs the image as desired.
I have also tried using
Code:
$this->output->set_header('Content-type: image/jpg');
$this->output->set_output($content);
Any help here would be of much appreciation.
Thanks and happy new year.