Display images to index.ctp

Good night.

I’ve trouble when display images feedback from ctp. Before show the image, I’ve success save images and place to folder C:\xampp\htdocs\sopigamboksutinem\webroot\files\Feedbacks\photo

I used plugin Josegonzalez/Upload to save image and success work.

The problem is, while I want to display images in index.ctp, below this

<?php foreach ($feedbacks as $feedback): ?>
  <td><?php echo $this->Html->image('/webroot/files/Feedbacks/photo' . $feedback->photo, array('height' => '40', 'width' => '40', 'fullBase' => true, 'plugin' => false)); ?></td>
<?php endforeach; ?>

I hope that someone help me to fix it, thanx good night

What’s not working about this? Is it as simple as adding another / after Feedbacks/photo, if that is indeed a folder as you’ve said?

1 Like

here, Mr.Zuluru. The photo doesn’t show in index.ctp. I hope you will guide me to fix it, thanx

Have you looked at the HTML there? What URL is it trying to load for the image? What is the actual URL that the image can be viewed at?

Hi @arizzoye
I think you should use absolute paths
$this->Html->image(WWW_ROOT . ‘/files/Feedbacks/photo’ . $feedback->photo, array(‘height’ => ‘40’, ‘width’ => ‘40’, ‘fullBase’ => true, ‘plugin’ => false)); ?>

Hope it helps you.

when I test below script,

<?php echo $this->Html->image(WWW_ROOT . 'files\Feedbacks\photo' . $feedback->photo, array('height' => '40', 'width' => '40', 'fullBase' => true, 'plugin' => false)); ?>

the result source code in firefox browser, show this

<td><img src="sopigamboksutinemC:\xampp\htdocs\sopigamboksutinem\webroot\files\Feedbacks\photoBanyak.png" height="40" width="40" alt=""/></td>

if code above I’m execute in browser, the picture doesn’t display that I want.
I hope any idea from someone to fix it, thanx

thanx mr.Zuluru, I’ve try possible code, truely I was wrong writing folder path.
Below code is running, I have tested

<td><?php echo $this->Html->image('/webroot/files/Feedbacks/photo/' . $feedback->photo, array('height' => '40', 'width' => '40', 'fullBase' => true, 'plugin' => false)); ?></td>

the picture feedbacks in index.ctp below this

Thanx @diep.doTMS

I have try below code, and successfull works

<td><?php echo $this->Html->image('/webroot/files/Feedbacks/photo/' . $feedback->photo, array('height' => '40', 'width' => '40', 'fullBase' => true, 'plugin' => false)); ?></td>

once again, thanx @diep.doTMS for guide me, enjoy the coffee

1 Like