0

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"/>
Biswajit_86
  • 3,661
  • 2
  • 22
  • 36
Freddie
  • 125
  • 1
  • 3
  • 14

1 Answers1

0

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 ^_^

Biswajit_86
  • 3,661
  • 2
  • 22
  • 36
owis sabry
  • 154
  • 9
  • I understand your point but is not working. Are you sure about = IMG_DIR ;?> – Freddie Jul 10 '15 at 00:10
  • oh ! , i forgot to tell you that you can't write the path like this: C:/xampp/htdocs/hyperstore/images/ if you use a local server use it like this : http:localhost/your_project/images/ then it will work for more information see this http://stackoverflow.com/questions/23969953/not-allowed-to-load-local-resource-file-c-jpg-java-ee-tomcat – owis sabry Jul 10 '15 at 00:55
  • could you write the error message? right click ->inspect element -> console – owis sabry Jul 11 '15 at 10:23
  • define("IMG_DIR ","project/folder_a/folder_a1/"); try this according to your files name – owis sabry Jul 14 '15 at 22:32