2010-12-16 119 views
0
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'; 

伙计们,任何想法有什么不对?图像文件无法正常工作的绝对路径

回答

1

您需要使用Web服务器根目录而不是文件系统根目录。

如果您的主页是/var/www/html/index.html,您的图片是/var/www/html/images/delete.png,那么您的图片href应该是/images/delete.png

3

可能是因为你在混合目录路径和URI。您的脚本所在的目录不同,它是您网站中的URI。您应该定义一个ROOT_URI常量,它将保存应用程序的顶级URI并使用它。

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

而不是使用ROOT_DIR尝试http://".$_SERVER["SERVER_NAME"].'/images...