To render the images directly from the database, you need to output an
appropriate mime type header then send the image data to the caller.

It's doable in cake, but you need to jump through a few hoops.

You certainly don't need to write the image to disk to serve it up to
the caller, that would be highly inefficient, and you'd be better off
writing the image to disk in the first place rather than storing in the
database if you were going that route.

As to whether serving up images directly from the database vs from the
file system via a php wrapper for access control is a sensible way to go
- that's a whole different discussion.

-- 
Regards,

Miah


-----Original Message-----
From: Steve Found <[email protected]>
Reply-to: [email protected]
To: [email protected]
Subject: Re: Displaying Images from Database
Date: Mon, 21 May 2012 12:21:42 +0100
Mailer: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430
Thunderbird/12.0.1

On 21/05/12 11:42, teji infin wrote: 
> Actually i am storing my images in my mysql database using image
> longblob named entry..
> 
> 
> On Mon, May 21, 2012 at 4:07 PM, LITTO CHACKO <[email protected]>
> wrote:
>         if u stored your image in webroot folder u can display images
>         rightly. but if u uploaded images out of webroot folder then u
>         have to use some imagecontroller to set path:- 
>         like this:-
>         ?php
>         
>         
>         class ImagepathController extends AppController{
>         
>         function index(){
>         $query = $this->params->query;
>           $file    =   $query['file'];
>             $width    =    $query['width'];
>             $height    =    $query['height'];
>         
>         
>             $base    =    Configure::read('MediaDir').'projects/';
>              $filePath    =    $base.$file;
>         
>             if(file_exists($filePath)){
>                 list($imwidth,$imheight,$type, $attr) =
>          getimagesize($filePath);
>                 if($imwidth>=$imheight){
>                     $per        =    $imwidth/$width;
>                     $cwidth        =    $imwidth/$per;
>                     $cheight    =    $imheight/$per;
>                 }else{
>                     $per        =    $imheight/$height;
>                     $cheight    =    $imheight/$per;
>                     $cwidth        =    $imwidth/$per;
>                 }
>                 if($imwidth<=$width && $imheight<=$height){
>                     $cwidth=$imwidth;
>                     $cheight=$imheight;
>                 }
>                 $extt    =    explode('.',strtolower($file));
>                 $ext    =    $extt[count($extt)-1];        
>                 ob_start();
>                 if($ext=='jpeg' || $ext=='jpg'){
>                     header('Content-type: image/jpeg');
>                     $im=imagecreatefromjpeg($filePath);
>                     $dest    =    imagecreatetruecolor($cwidth,
>         $cheight);
>                     imagecopyresized($dest,$im,0,0,0,0,$cwidth,
>         $cheight,$imwidth,$imheight);
>                     imagejpeg($dest);
>                 }
>                 if($ext=='png'){
>                     header('Content-type: image/png');
>                     $im=imagecreatefrompng($filePath);
>                     $dest    =    imagecreatetruecolor($cwidth,
>         $cheight);
>                     imagecopyresized($dest,$im,0,0,0,0,$cwidth,
>         $cheight,$imwidth,$imheight);
>                     imagepng($dest);
>                 }
>                 if($ext=='gif'){
>                     header('Content-type: image/gif');
>                     $im=imagecreatefromgif($filePath);
>                     $dest    =    imagecreatetruecolor($cwidth,
>         $cheight);
>                     imagecopyresized($dest,$im,0,0,0,0,$cwidth,
>         $cheight,$imwidth,$imheight);
>                     imagegif($dest);
>                 }
>                 exit();
>             }else{
>                 ob_clean();
>                 ob_start();
>                 header('Content-type: image/jpeg');           
>                 $dest    =    imagecreatetruecolor(300,300);
>           
>                 imagejpeg($dest);
>                 exit();
>                
>             }
>         }
>         
>         
>         }
>         
>         
>             ?>
>         
>         On Mon, May 21, 2012 at 4:04 PM, Teji <[email protected]>
>         wrote:
>                 Can anyone tell me how to display images from my
>                 database to my
>                 webpage.
>                 
>                 i upload the images in database using longblob
>                 datatype.
>                 
>                 anyone help plz..
>                 
>                 --
>                 Our newest site for the community: CakePHP Video
>                 Tutorials http://tv.cakephp.org
>                 Check out the new CakePHP Questions site
>                 http://ask.cakephp.org and help others with their
>                 CakePHP related questions.
>                 
>                 
>                 To unsubscribe from this group, send email to
>                 [email protected] For more
>                 options, visit this group at
>                 http://groups.google.com/group/cake-php
>         
>         
>         
>         
>         -- 
>         Litto Chacko
>         
>         Axtec Softwares
>         
>         
>         -- 
>         Our newest site for the community: CakePHP Video Tutorials
>         http://tv.cakephp.org 
>         Check out the new CakePHP Questions site
>         http://ask.cakephp.org and help others with their CakePHP
>         related questions.
>          
>          
>         To unsubscribe from this group, send email to
>         [email protected] For more options, visit
>         this group at http://groups.google.com/group/cake-php
>         
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and
> help others with their CakePHP related questions.
>  
>  
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this
> group at http://groups.google.com/group/cake-php
Assuming you wish to display the images on a web page, you would need to
extract the image from the database and write it to disk as a jpeg,gif
or png image. The web page can then display it through an img tag.

Alternatively with HTML5, you could try extracting the image and
displaying it in a canvas element which would be a fun project.

This might be of interest:
http://bakery.cakephp.org/articles/grzegorzpawlik/2009/03/04/imagebehavior-best-from-database-blobs-and-file-storage





-- 
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help
others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
[email protected] For more options, visit this group
at http://groups.google.com/group/cake-php

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to