aymanko
aymanko

Reputation: 39

output image in php page

enter image description here

thank you so much for your hard work, my issue hopefully is not that complicated. I'm trying to display few images in my website, and it won't display, the php page and the image are on the same directory, and when i try the same directory on html file it works fine, but when I try to use the same directory on php file the pic look broken icon,and won't appear.. I also tried png and jpg image, still nothing coming out..

please guys..

this is the simple code, i tried to test,

    <html>
<head><title> hello </title></head>
<body>
<?php $image = 'zz.png'; ?>

<img src= "<?php $image ?>" style="width:304px;height:228px;">


hello world.. 
</body>
</html>

Upvotes: 0

Views: 3884

Answers (3)

Tino R&#252;b
Tino R&#252;b

Reputation: 809

Print the var $image with echo (and close the image tag with a frontslash at the end of the tag for correct html):

<img src= "<?php echo $image; ?>" style="width:304px;height:228px;" />

Other possible reasons the image is not displayed (after you print the image name out with echo):

  • the value of your var $image mismatched with the imagename.
  • the image is not stored in the same folder as the php document.
  • your image is saved in CMYK mode, and not in RGB.
  • the file permission of the image
  • configuration of the webserver (apache for ex.)

Upvotes: 2

Benjamin L&#252;cking
Benjamin L&#252;cking

Reputation: 136

You have to print out the $image variable by using the echo function. Your code should be looking like this:

<?php
    $image = 'zz.png';
?>
<html>
    <head>
        <title> hello </title>
    </head>
    <body>
    <img src= "<?php echo $image; ?>" style="width:304px;height:228px;">

    hello world.. 
    </body>
</html>

Furthermore, it looks better when you put all your php stuff before the HTML code, that does not necessarily have to be inside HTML.

If it is still not working, you are probably viewing your html file locally. You have to view it remotely by using a http web server with a php interpreter included. You can easily set up one with XAMPP.

Remember that it does not work by just opening your file in a browser.

Upvotes: 1

Daniel Coturel
Daniel Coturel

Reputation: 106

I think you should replace this line:

<img src= "<?php $image ?>" style="width:304px;height:228px;">

With this:

<img src= "<?php echo($image) ?>" style="width:304px;height:228px;">

Since echo() is the function that generates the output.

Upvotes: 0

Related Questions