Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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';

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top