How can I echo an image using PHP?
This is what I have:
echo "<img src="Images/Picture.GIF">";//This should echo my image
If by "echo" you mean outputting the image in a browser, you need to read it first then send it with echo
. Something like this should work:
$content = file_get_contents('Images/Picture.GIF');
header('Content-Type: image/gif');
echo $content;
You cant echo
an image using PHP.
echo — Output one or more strings
echo
is for strings only. However, you can echo
the image source - img src=""
Just make sure you put the picture extension at the end of the file you are grabbing. - .jpg .png
etc.
You just need to grab the image source from somewhere.
Example (using $_GET
):
<?php
if($_SERVER['REQUEST_METHOD']=='GET'){
$img_src=$_GET['img_src']
}
echo "<img src='/images/test/" . $img_src . "' alt='img'>";
?>