1

Trying to use php to link to an image in a different folder than the file I am currently in but the image isn't showing.

Here's the path file:

<?php
if (!defined("ROOT_PATH")) define ("ROOT_PATH", realpath(dirname(__FILE__)));
if (!defined("BASE_URL")) define ("BASE_URL", "http://localhost/stnresp");
?>

Here's the code I am using at the moment:

<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>

I can't understand why the root path isn't taking the link to the root directory and then through to the image? What am I missing?

Thanks

1 Answer 1

1

realpath defines the physical path of the file, instead the src attribute of the image needs url path.

In your case you have to use BASE_URL instead of 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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.