When should I include ".. /" in the path to a include or image?

Asked

Viewed 71 times

3

I have this doubt because time is necessary only the way pasta/arquivo.ext and time I have to put ../pasta/arquivo.ext.

Is there any rule?

  • It is true there is yes, I will write down to answer another time

  • I closed, but if you disagree please vote to reopen.

  • I looked before I asked, but that title did not come to mind...

  • The big problem is that the stackoverflow search engine is bad, it does not recognize score and bar :/, nor typing with quotes "../"

  • um...tá Exp"r"icado

1 answer

6


Of course I do, there’s a rule one.jpg in the file index.php within the following structure:

-index.php
-imgs
    - one.jpg
    - two.jpg
    ...

For this case above you would use so:

imgs/one.jpg

Another case will be:

-views
    - index.php
-imgs
    - one.jpg
    - two.jpg

Now you’d have to declare that you want to go back 1 level (../) in the directory hierarchy, the starting point being index.php, being like this:

../imgs/one.jpg

That is, with this "statement" (../) are at the level of views and of imgs, then yes, you can enter imgs and complete the path with the image you want, and the same goes for longer:

-public
    -views
        - index.php
-assets
    -imgs
        - one.jpg
        - two.jpg

Here you would have to go back two levels in the structure so you can "enter" the folder assets and have access to imgs and then to the image, ../../assets/imgs/one.jpg

All these uses imply the use of relative path, and not the absolute path

Browser other questions tagged

You are not signed in. Login or sign up in order to post.