Error displaying image in pdf directory - Cakephp 3

Friends, I set up a shopping cart with one where I can insert several products. In addition to the cart, I needed to export this list in pdf. When generating the pdf, all items related to the product are displayed, except the product image.

I have two fields in the table where I store the image path: path AND img_product.

I have an example of the filled fields:

path: img/img_products/bd9399cfadbbb51639a033a6a81208bd04cf4b85
img_product: cell.jpg

I’m trying to generate the image this way:

<?php foreach((array) $this->request->getSession()->read('cart') as $index=>$cart): ?>

<?= $cart->has('product') ? $this->Html->image('/'.$cart->product->path.$cart->product->img_product, array('width' => '150px', 'class' => 'card-img-top')) : ''?>

<?= $cart->product->name ?>

<?php echo number_format($cart->product->price, 2, ',', '') ?></p>

Quantity: <?= $cart->quantity ?>
Subtotal: R$ <?php $sub = ($cart>product->price * $cart->quantity);
             echo number_format($sub, 2, ',', '');

<?php endforeach; ?>

That is, this line does not work:

<?= $cart->has('product') ? $this->Html->image('../'.$cart->product->path.$cart->product->img_product, array('width' => '150px', 'class' => 'card-img-top')) : ''?>

My folder is located at: …/webroot/img/img_products

I appreciate any comments

based on the ‘path’ and ‘img_product’ sample data you show, your concatenated path will not have a directory separator before the file name.

I’m not too sure about the preceding ‘…/img/’ either. I think it may end up needing to be ‘/img/’.

But once you fix the missing separator before the file name you can easily dial in the exact details of your path by examining the html your code produces and comparing it to a working image path in your app.

Hi @ecei,

As @dreamingmind suggested, you are missing directory separator(DS) when concatenating the path and filename.

<?= $cart->has('product') ? $this->Html->image('/' . $cart->product->path . DS . $cart->product->img_product, array('width' => '150px', 'class' => 'card-img-top')) : ''?>

I added the DS, but nothing happened. Detail: The path of the image and the name of the image are together in the title of the image.

Captura de tela de 2020-07-22 09-12-12

Got it. I did it this way in the shopping cart and it worked. I just copied the code from Orders / index.ctp to Orders / pdf / download.ctp. All information is displayed except the image.