[TYPO3] Display Image From MySQL Database

Lee M. Childress leemchildress at hotmail.com
Sat Sep 13 02:11:58 CEST 2008


 Why do you store image in MySQL database ? It's not really efficient  in term of performance and memory usage for your application ... See you Dominique Feyer
 
I store images within the related database so that when that record is deleted, I do not have to worry about image clean-up. They are deleted along with the master record. Additionally, if two users upload an image with the same filename, it doesn't matter.
 
Back in the days when I used ModX (don't flog me, I don't use it anymore) I used this method and it worked great. For some reason Typo3 doesn't like me doing this. Le 12 sept. 08 ? 21:45, Lee M. Childress a ?crit : >> 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