Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ilex01's avatar

How do I access an image inside the public_html directory outside of the public_html directory

I've 2 folders:

  • public_html
  • lfg

See my folders by following this link: https://i.gyazo.com/c61d56a5d8742e6eadff570672cc0dca.png

How do I access an image inside the public_html directory:

<img src="point To The Outside Of The Public Html Directory" />
/home/lfg/public_html/storage
/lfg/storage/app/public

Here is located the file:

/lfg/storage/app/public/avatar/user.png

https://i.gyazo.com/12ee2e798002f8a53ebdcf0ba3c7789a.png

0 likes
9 replies
tykus's avatar

The point of directories outside of the public root is that the contents should not be publicly accessible. You would need to either (i) symlink the directory into public, or (ii) make a Route to get the contents from the non-public directory

1 like
ilex01's avatar

@tykus I've tried to symlink like this:

In public_html:

<?php
symlink('/home/lfg/lfg/storage/app/public', '/home/lfg/public_html/storage');

But with no success

tykus's avatar

@ilex01 does your host allow symlinks? Do you have CLI access to run this manually? Is there a cpanel tool to achieve this?

tykus's avatar

@ilex01 how is this application being served? You have a Laravel application inside lfg? Is public_html the effective public directory for this application?

idew's avatar

<img src="" /> runs in the browser so it doesn't have access to your local filesystem. It can only load images you have exposed to the internet. So src should equal the URL of the image. Not its path on your local filesystem.

idew's avatar

@ilex01 If the Laravel application is publicly accessible, it should be https://YOURAPPDOMAIN/avatar/IMAGENAME.

Although, since it looks like those avatar images were uploaded and have randomly generated names, I'd create an API endpoint in the Laravel app that returns either the URL for an avatar image or the avatar image itself for a given user.

Please or to participate in this conversation.