Reputation: 39
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
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
):
$image
mismatched with the imagename.CMYK
mode, and not in RGB
.Upvotes: 2
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
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