-2

My absolute URL is linked to my public folder:

<img src="{{ absolute_url(asset('img/logo/image.jpg')) }}" alt="image"/>

It works fine like this, but in one case I need to load an image with an absolute URL but not to the public folder, instead, the image is in another folder that is on the same level then my public folder. I tried something like this:

<img src="{{ absolute_url(asset('../myfolder/private/image.jpg')) }}" alt="image"/>

But it is not working.

peace_love
  • 6,229
  • 11
  • 69
  • 157
  • Why do you need that in the first place? Why not put assets in the asset folder? – Nico Haase Jun 02 '20 at 18:24
  • Because we programmed a module that is generating thumbnails within that modul. It is complicated to explain this all here, but for this it is necessary – peace_love Jun 02 '20 at 18:26
  • I would assume that this is a security feature, so assets can not be linked from outside the configured folder – Nico Haase Jun 02 '20 at 18:30
  • Look into [Packages](https://symfony.com/doc/current/components/asset.html) possibly. Do that on the server-side as pass it in as a twig variable since this is a one-off. If you need it multiple times you should be able to create a quick twig extension to do handle your logic. – Chris Haas Jun 02 '20 at 18:58
  • If you u need it in `DOMPDF`, then use the physical path – DarkBee Jun 03 '20 at 06:53
  • @DarkBee Yes, this is my problem. I cannot figure out how to create a physical path to the root – peace_love Jun 03 '20 at 13:20
  • You could pass the absolute path from your controller to twig with something like `__DIR__ . '/../../path/to/file/image.jpg';` – DarkBee Jun 03 '20 at 13:53

1 Answers1

0

public is your webroot, you can't access anything outside public directly in your browser (and for good reasons, this means you can't read the source code of any application!)

If you want to make something from outside the public directory available, either move it (or symlink) it into the public directory, create a new webroot, or write a custom Symfony controller to show the assets to your clients (make sure to have proper caching with the latter solution).

Wouter J
  • 41,455
  • 15
  • 107
  • 112