Reputation: 355
I am trying to serve an image to html via php script. But I am stuck and its not working :-( Below is my image.php script
<?
$_GET['f'] = 'all_three.jpg';
$image = null;
$image = file_get_contents($_GET['f']);
header("Content-Type: image/jpeg");
echo $image;
?>
and below is my index.html
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Page Title</title>
</head>
<body>
<img src="image.php" alt="Image" />
</body>
</html>
The link to image is "hard-coded" inside the php, all I am doing is calling "image.php" to serve that hardcoded image and it does not work! What am i doing wrong?
Upvotes: 1
Views: 122
Reputation: 944530
when I view->source after loading image.php, i can see the php script
Either:
You are depending on short tags, but your server is configured to not support them.
Their use is not recommended, stop using them. Use <?php
instead of <?
Or:
Your server does not support PHP. Install PHP on it.
Upvotes: 4
Reputation: 1231
The error is on Content-Encoding, what's Text editor are you use ? Notepad 6.x ?
If yes please try:
Encoding > Encode in UTF-8 without BOM
BOM make php file have a more content and image doesn't accept another content else image
Upvotes: 0