Reputation: 2386
echo '<img src="../../images/delete.png" id="aaa" />aaa '; (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
Reputation: 17169
instead of using ROOT_DIR try http://".$_SERVER["SERVER_NAME"].'/images...
Upvotes: 1
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
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 '; (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