[ACCEPTED]-A php file as img src-image-processing
Directly from the php fpassthru docs:
<?php
// open the file in a binary mode
$name = './img/ok.png';
$fp = fopen($name, 'rb');
// send the right headers
header("Content-Type: image/png");
header("Content-Length: " . filesize($name));
// dump the picture and stop the script
fpassthru($fp);
exit;
?>
As an explanation, you 2 need to pass the image data as output from the script, not html 1 data. You can use other functions like fopen
, readfile
, etc etc etc
"<img src=\"btn_search_eng.jpg\" />"
is not valid image data. You have to actually 2 read the contents of btn_search_eng.jpg
and echo them.
See here for the 1 various ways to pass-through files in PHP.
UPDATE
what you can do without using include
as said below 2 in the comments:
try this:
<?
$img="example.gif";
header ('content-type: image/gif');
readfile($img);
?>
The above code 1 is from this site
Original Answer
DON'T try this:
<?
header('Content-Type: image/jpeg');
include 'btn_search_eng.jpg'; // SECURITY issue for uploaded files!
?>
If you are going to use header('Content-Type: image/jpeg');
at the top of your 4 script, then the output of your script had 3 better be a JPEG image! In your current 2 example, you are specifying an image content 1 type and then providing HTML output.
What you're echoing is HTML, not the binary 4 data needed to generate a JPEG image. To 3 get that, you'll need to either read an 2 external file or generate a file using PHP's 1 image manipulation functions.
if you use base64 it would be
<?php
header('Content-Type: image/jpeg');
echo(base64_decode('BASE64ENCODEDCONTENT'));
?>
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.