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