0

i'm trying to display an image using php to include its full path but the picture doesn't want to show up, the code i'm using is :

<img src="<?php echo $_SERVER['DOCUMENT_ROOT'] . 'Romeo/Yoomak/pix/Logo9.png';?>" width="200" height="200" alt="Logo"/>

No Error shows up in the output but the picture doesn't show up so what should i do ? help pls and thnx in advance.

That's what i get: image not showing up as shown in this SS

13
  • What do you see when you take a look at the generated path within src? Commented Jul 23, 2021 at 19:07
  • @B001ᛦ I don't see anything abnormal, everything seems ok and the page loads normally but the picture is not showing up on it Commented Jul 23, 2021 at 19:17
  • everything seems ok... What does that mean? Can you copy and paste the path into the browser and see if the picture loads directly? Commented Jul 23, 2021 at 19:23
  • What do you see when you echo the generated path with src? Commented Jul 23, 2021 at 19:25
  • @renshul I just added a link with a SS showing what i get please check it Commented Jul 23, 2021 at 19:46

2 Answers 2

1

You need to add "/" before Romeo. Or you set an incorrect path here: 'Romeo/Yoomak/pix/Logo9.png'

Sign up to request clarification or add additional context in comments.

Comments

1

The Document Root is the directory on filesystem of the computer running the HTTP server that corresponds to the / path in the server's URL.

The browser will ask the HTTP server for an HTTP URL.

The browser can't read files directory from the server's filesystem (it would be a dreadful security problem if it could).

Assuming that the file really is in that path from the document root, you should have simply:

<img src="/Romeo/Yoomak/pix/Logo9.png" width="200" height="200" alt="Logo"/>

NB: Logo is pretty dreadful alt text

3 Comments

I thought this question was a dupe but I can't find an exact dupe of it (probably ambiguous wording)
@Quentin It works fine when i do it plain html like u did but the thing is when i try to include this same page that has the image into other pages which are in different directory the image disappears because this plain html way is not dynamic, that's why i tried to use php in the img src attribute in order to be able to show the image wherever i include its page in
@Ahmus — Paths starting with a / are absolute. It shouldn't matter where the HTML document is so long as it is on the same server (and hostname/port). Maybe you missed the / at the start of the URL in this answer.

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.