0

render.php

$form = '<b>Hi</b><br /><img src="test.jpg" /><br />New File';

echo $form;
header("Content-Type: image/png");
imagejpeg($form);

But this code not work

I want this page render to img file :

<img src="render.php" />
Mohammad
  • 28
  • 2
  • 7

2 Answers2

0

you are trying to output both HTML and image-data - that doesnt make any sense. Instead you should put an HTML-img-tag into your website, the src-attribute being render.php which sets the header via header() and directly outputs image data - without any additional HTML.

https://stackoverflow.com/a/1851856/351861

Community
  • 1
  • 1
specializt
  • 1,913
  • 15
  • 26
0

You should use extra php file for images, something like:

<img src="render.php?id=15" />

Because if your php script returns only one picture it is used wrong. so you pass it what image to show. And render.php might be something like

$pic_id = (int)$_GET['id'];// cast to int because only numbers are allowed here
$pic_path = 'assets/img/';
$f = $pic_path.$pic_id.".jpg";// it's just an example so it's simplyfied
header("Content-Type: image/png");
imagejpeg($form);

The point here is that you can check user's permissions to see the picture very flexible and log some data about downloader.

maxpovver
  • 1,580
  • 14
  • 25