【问题标题】:absolute path for image file not working图像文件的绝对路径不起作用
【发布时间】:2011-05-26 07:49:44
【问题描述】:
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';

各位,知道怎么回事吗?

【问题讨论】:

    标签: php image file path absolute


    【解决方案1】:

    可能是因为您混合了目录路径和 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';
    

    【讨论】:

      【解决方案2】:

      您需要从 Web 服务器根目录工作,而不是文件系统根目录。

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 2013-07-06
          • 1970-01-01
          • 2015-08-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-12-23
          相关资源
          最近更新 更多