0

Here is my folders structure:

- var/www/project
  - public
    - images
      - image1.png
    - style.css
  - storage
    - other_images
      - image2.png

I'm trying to access the picture with background-image: url("../storage/other_images/image2.png");

However the image is not displayed. But if I try to access another image like this: background-image: url("/images/image1.png"); it works.

And if I try background-image: url("../public/images/image1.png"); it fails again. Which should work as I'm basically providing the same url.

Another weird thing is that background-image: url("../images/image1.png"); also works (should it?). I can even write background-image: url("../../../../../../../images/image1.png"); and it still finds it.

Is this how it is supposed to be?

The main question is: how do I properly specify url for the image2.png?

1 Answer 1

1

Your public and storage is in same level and storage becomes not accessible via URL, because it's not under web root.

Also ../somedir/image.png will be interpreted from current directory. Better always specify /somedir/image.png (with first character / as it specifies root directory).

Sign up to request clarification or add additional context in comments.

2 Comments

I remember url being relative to css file's location. So the solution is to move image2.png inside images/ ?
@Linas If your URL is not in CSS, but in image tag, than it may change. And yes, move all images to web accessible location

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.