[ACCEPTED]-A php file as img src-image-processing

Accepted answer
Score: 13

Use readfile:

<?php
header('Content-Type: image/jpeg');
readfile('btn_search_eng.jpg');
?>

0

Score: 8

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

Score: 5

"<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.

Score: 5

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!

?>
Score: 2

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.

Score: 2

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.

Score: 0

if you use base64 it would be

<?php
    header('Content-Type: image/jpeg');
    echo(base64_decode('BASE64ENCODEDCONTENT'));
?>

0

More Related questions