[TYPO3] Display Image From MySQL Database

Lee M. Childress leemchildress at hotmail.com
Fri Sep 12 21:45:02 CEST 2008


 
I'm going bonkers. I am using an image tag <img src="render_image.php?db=0&id=317" alt="" /> to display an image contained in a mysql database. I am using the following script to display the image:
 
/** * RENDER IMAGE * ============ */    if ($_GET['id'] && $_GET['db']) {     if (strtolower($_GET['db']) == '0') {      $_db = 'events';      $new_width = 200;     }     if (strtolower($_GET['db']) == '1') {      $_db = 'recipes';      $new_width = 200;     }        $sql = new MySQL;        $sql->mysql_query = 'SELECT image FROM ' . $_db . ' WHERE id = ' . $_GET['id'] . ' LIMIT 1';        $sql->connect();        $_row = mysql_fetch_array($sql->mysql_result);        if ($_row['image']) {            $_image = base64_decode($_row['image']);            $width = imagesx($_image);   $height = imagesy($_image);   $new_height = $height * ($new_width/$width);   $image_resized = imagecreatetruecolor($new_width, $new_height);   imagecopyresampled($image_resized, $_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);   header('Content-type: image/jpeg');   imagejpeg($image_resized);   imagedestroy($image_resized);        }    }
 
I keep getting a broken image. Any ideas?
 
Thanks for your help.


More information about the TYPO3-english mailing list