0

I'm curious about this, and I think I'm half way to a "no", but I'm not an expert.

Having a directory structure like the following, and being public the public root of a website:

directories and files: www dir. Inside it public and not public dirs. Inside public, index.php. Inside not-public, img.jpg and abc.php. .

Every .php file shown can be used to generate the webpage.

But, in the generated HTML, img.jpg can't be found. Not with relative nor absolute paths, as far as I tested.

Is there a way to display this image on this website without moving it into public directory? (Permission changes and witchcraft allowed.)

If not, then why?

Fahed
  • 149
  • 1
  • 8

1 Answers1

1

Public media (images, javascript etc.) should be accessible from public directory, but there are solutions to work around this.

You can display PHP code as an image.

Output an Image in PHP

Jsowa
  • 4,188
  • 4
  • 23
  • 35
  • Thanks for your answer. On the question you linked, they use ```header('Content-Type:image/jpeg');```, I understand that will show the image only. While that answer this question; are you aware of a way that would allow to use the image as a part of a bigger content? (as an example: text, img, more text) – Fahed Jun 17 '20 at 11:30
  • It works the same. URL to image called with PHP may be ended with `.php` or even `.jpg` when you join it with proper `mod_rewrite` settings. – Jsowa Jun 17 '20 at 13:17
  • You can create kind of proxy for your images. – Jsowa Jun 17 '20 at 13:18