尝试使用php链接到与我当前所在文件不同的文件夹中的图像,但该图像未显示。
这里是路径文件:
<?php
if (!defined("ROOT_PATH")) define ("ROOT_PATH", realpath(dirname(__FILE__)));
if (!defined("BASE_URL")) define ("BASE_URL", "http://localhost/stnresp");
?>
这是我目前正在使用的代码:
<div class="logo-image">
<a href="<?php echo BASE_URL . '/index.php'; ?>"><img class="header-logo" src="<?php echo ROOT_PATH . '/assets/images/stn-logo-cropped.png'; ?>" alt=""></a>
</div>
我不明白为什么根目录路径没有链接到根目录然后再链接到映像?我想念什么?
谢谢
[realpath
定义文件的物理路径,而不是图像的src
属性需要url路径。
在您的情况下,您必须使用BASE_URL
而不是ROOT_PATH
:
<div class="logo-image">
<a href="<?php echo BASE_URL . '/index.php'; ?>"><img class="header-logo" src="<?php echo BASE_URL . '/assets/images/stn-logo-cropped.png'; ?>" alt=""></a>
</div>