1

I need to insert php code within a text. It is an image but uses an absolute path through php. I would like to execute but the image is not displayed within the text.

<img class="image-left" src="<?php $_SERVER['DOCUMENT_ROOT']?>/abuelo/abuelo.png"/>Since the founding of Grandpa in 2003 we have offered a different type of shopping. We have always had service...

I always use in my projects Because I find very useful, if you change the place .php file or meta in a folder always find the images.

I would be very utilizad it can also be included in the database, in case I need to show information with your image added elsewhere on the page regardless of where the file is hosted.

Is there any way to insert the image in the database and make it work?

6
  • DOCUMENT_ROOT will give you the absolute file path so unless you're running this on localhost, it won't work. Commented Nov 25, 2015 at 10:16
  • I'm on localhost, when placed a statement in my code php html works perfect. The problem is to put code in the SQL database and want to call it from the page. Commented Nov 25, 2015 at 10:20
  • In the page source code php code as if text is displayed. Php code should not appear in the source code of the web, I think there is a problem that is beyond me. <span class="informacion"> <img class="image-left" src="<?php echo $_SERVER['DOCUMENT_ROOT']?>/novedades/grandpa.png"/><strong>The sun</strong>, si Commented Nov 25, 2015 at 10:25
  • @PlayerWet Your question is not understandable to me. Based on your question, I would be very utilizad it can also be included in the database..., what is this it you want to include in the database? Commented Nov 25, 2015 at 10:48
  • All I need is to store an image left-aligned in a text. All that we have already inserted into the database. But the image to be displayed've put that sentence php to avoid problems with the route, as always will take the root directory. But when it comes to bring the text to the image included my web image is not displayed. The php statement is displayed as plain text. I hope you understand me well, I'm using google translator because I'm Spanish, I'm sorry. Commented Nov 25, 2015 at 10:56

1 Answer 1

3

All you need is an echo

<img class="image-left" src="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/abuelo/abuelo.png"/>Since the founding of Grandpa in 2003 we have offered a different type of shopping. We have always had service...

Edited:

The problem is, you are referencing your image as,

C:/wamp/www/

which will never work. You should be referencing it as localhost. Like this:

<img src="<?php echo "http://" . $_SERVER['SERVER_NAME']; ?>/abuelo/abuelo.png" />
Sign up to request clarification or add additional context in comments.

8 Comments

The call from the html document thus do <? php echo $ information?> I mean, I guess you consider that area as a miss php, and could not run an echo inside another echo.
check the image path again. Use ctrl+u on the browser to see what path it is displaying.
And yes, php is will error because of missing semicolon;, add it. It should be <?php echo $information; ?>
Error php does not give me the information database of the sample well. What does not read as php code is what's inside the table database. I tried adding the; End of sentence and remains the same
@RajdeepPaul - If you only have one statement within the PHP-tags it should work without ;
|

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.