Search code examples
phpstreamphp-stream-wrappers

Http request to php stream image


I have a php file, when you open it, a picture is going to be downloaded and opened. Here is my code:

header('Content-type: image/jpeg');
$stream = fopen('php://output', 'w'); // Stream to browser like with echo
$MadelineProto->download_to_stream($messageMediaPhoto, $stream);

It's ok when you open directly. But when I send an ajax request to the page, I get some long strange characters. (I want to display the image in html src)

any idea would be appreciated.


Solution

  • You need to add your php file to the src attribute of the image tag. For example if your php file is called image.php, then you can use the following html code to display the image:

    <img src='image.php' width='image-width-in-px' height='image-height-in-px' />