10-28-2009, 11:15 PM
[eluser]Unknown[/eluser]
Hey guys,
My current problem is loading images from MySQL database to the view in CI.
The above is the code I used in a PHP file (outside CI) for testing purposes, which successfully loaded the image from the database.
I pasted the exact same code on a view in my CI folder(which I figure should work), and ran it through a controller function which redirected to this view and what came out was gibberish instead of the image.
The 'photo' field type is of 'blob' format.
I wonder if there is any extra lines of code I missed out.
Thanks in advance!
Hey guys,
My current problem is loading images from MySQL database to the view in CI.
Code:
<?php
$val = "1";
$con = mysql_connect("localhost","root","bla");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("studentDB", $con);
$val = 1;
$dbQuery = "SELECT photo FROM students WHERE stud_id=$val";
$result = mysql_query($dbQuery) or die("Couldn't get file list". mysql_error());
if(mysql_num_rows($result) == 1)
{
$photo = mysql_result($result, 0, "photo");
Header("Content-type: image/jpeg");
echo $photo;
}
else
{
echo "Record doesn't exist.";
}
?>
The above is the code I used in a PHP file (outside CI) for testing purposes, which successfully loaded the image from the database.
I pasted the exact same code on a view in my CI folder(which I figure should work), and ran it through a controller function which redirected to this view and what came out was gibberish instead of the image.
The 'photo' field type is of 'blob' format.
I wonder if there is any extra lines of code I missed out.
Thanks in advance!