如何将相同的路由写入位于不同文件夹中的不同文件的文件

Imagine that I have following folders and files:

  • folder_a/
    • file_a.php
    • folder_a1
      • img_a1.png
    • folder_a2/
      • file_a2.php

Is there a way that I can write only one route to img_a1.png no matter if I am on file_a.php or file_a2.php?

This is what I'm doing now:

To access img_a1.png from file_a.php:

 <img src="folder_a1/img_a1.png"/>

To access img_a1.png from file_a2.php:

<img src="../folder_a1/img_a1.png"/>

I don't understand your goals but, my answer may fit your requirement:

       define("IMG_DIR ","c://xampp/htdocs/project/folder_a/folder_a1/");

now you just write your code like that :

<img src="<?= IMG_DIR ;?>/img_a1.png">

now you don't need to specify the directories in every php file that in different categories also

I hope you can use this ^_^