Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

problem retrieving image from mysql table

images php coding issues or problems here.

Moderators: macek, egami, gesf

problem retrieving image from mysql table

Postby bghodsi » Fri Dec 30, 2011 12:42 pm

I have successfully uploaded images into my table (store) which has three fields (id, name and image)
Image data type is blob as expected.

what I am doing wrong with the following script?

Any assistance will be gladly considered.

<?php
$host = 'localhost';
$user = 'root';
$pw = '';
$db = 'databaseimage';


mysql_connect($host,$user,$pw);

mysql_select_db($db);

$sql = "select name from store where id='1'";

$result = mysql_query($sql) or die('Bad query at 12!'.mysql_error());

while($row = mysql_fetch_array($result,MYSQL_ASSOC)){

$db_img = $row['name'];
$type = $row['ext'];


}

$db_img = base64_decode($db_img); //print_r($db_img );

$db_img = imagecreatefromstring($db_img);
if ($db_img !== false) {
switch ($type) {
case "jpg":
header("Content-Type: image/jpeg");
imagejpeg($db_img);
break;
case "gif":
header("Content-Type: image/gif");
imagegif($db_img);
break;
case "png":
header("Content-Type: image/png");
imagepng($db_img);
break;
}


}
imagedestroy($db_img);
?>

Bob Ghodsi
bghodsi
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Nov 29, 2011 1:37 pm

Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron