How to get images from database in cakephp

#1

how to get images from database in cakephp

#2

Step 1: Explain what you mean by “get images from database”.
Step 2: Tell us about the database structure where the images are stored.
Step 3: Show us what you’ve tried, and explain what’s not working about it.

2 Likes
#3

i save my images in webroot after uploading by forms now i want to access these images on my index.ct form i save image name in database and images upload in webrooot my own directory

#4

See the docs, but something like:

<td><?php echo $this->Html->image('imgdogs/' . $quy->dogpic, array(
                                'class' => 'imgborder',
                                'alt' => ''
                            )); ?></td>

or just a regular image tag:

echo '<img src="' . DIR . 'upload/imgrecent/' . $row->pic4 . '" width="280" class="imgborder">';

DIR is a constant I use.

#5

plz inform me bro what’s mean by $row->pic4 we are fetching pic4 only or by this statment we can fetch all require images

#6

$row->pic4 is just his “placeholder”.
This should be replaced with your specific property.

#7

It should be obvious that if more than one you need to setup a foreach loop.

And handle if one is empty.

if (empty($row->your_pic)) {
                echo "";  // or a default // or however you need
            } else {
                // display the image
              
            }

If you are new to this stuff, I’d highly advise finding and taking some basic html, php, css, and JS tutorials.