图像文件的绝对路径不起作用
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';
伙计们,知道出了什么问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能是因为您混合了目录路径和 URI。您的脚本所在的目录与您网站中的 URI 不同。您应该定义一个
ROOT_URI
常量来保存应用程序的顶级 URI 并使用它。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.您需要从 Web 服务器根目录而不是文件系统根目录进行操作。
如果您的主页是
/var/www/html/index.html
并且您的图像是/var/www/html/images/delete.png
,那么您的图像 href应为/images/delete.png
。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
.而不是使用 ROOT_DIR 尝试
http://".$_SERVER["SERVER_NAME"].'/images...
instead of using ROOT_DIR try
http://".$_SERVER["SERVER_NAME"].'/images...