i need help
i need help

Reputation: 2386

absolute path for image file not working

echo '<img src="../../images/delete.png" id="aaa" />aaa&nbsp;&nbsp;&nbsp;';  (working fine)

//define( 'ROOT_DIR', dirname(__FILE__) );  is in a file at root folder.
//i able to use this ROOT_DIR to include class files without any problem
//BUT, when I use it with photo image, it just not working!

echo '<img src="'.ROOT_DIR.'/images/delete.png" id="bbb" />bbb';

Guys, any idea what's wrong?

Upvotes: 0

Views: 14003

Answers (3)

KJYe.Name
KJYe.Name

Reputation: 17169

instead of using ROOT_DIR try http://".$_SERVER["SERVER_NAME"].'/images...

Upvotes: 1

Brad Mace
Brad Mace

Reputation: 27886

You need to work from the web server root, not the file system root.

If your main page is /var/www/html/index.html and your image is /var/www/html/images/delete.png, then your image href should be /images/delete.png.

Upvotes: 2

RageZ
RageZ

Reputation: 27313

Probably because you are mixing directory path and URI. The directory where your script is located is different then it's URI in your website. You should define a ROOT_URI constant that would held the top URI of your application and use it.

echo '<img src="../../images/delete.png" id="aaa" />aaa&nbsp;&nbsp;&nbsp;';  (working fine)

//define( 'ROOT_URI', 'some/uri' );  is in a file at root URI.

echo '<img src="'.ROOT_URI.'/images/delete.png" id="bbb" />bbb';

Upvotes: 3

Related Questions