[使用PHP链接到SRC时未显示图像

问题描述 投票:0回答:1

尝试使用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>

我不明白为什么根目录路径没有链接到根目录然后再​​链接到映像?我想念什么?

谢谢

php html image filepath
1个回答
1
投票

[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>
© www.soinside.com 2019 - 2024. All rights reserved.