0
votes

I have used the construct <img src="http://yoursite.com/image.php?request_id=XXXX"> and it works well to serve images that may need some preprocessing. However, if image.php requires a lot of arguments, the src can become very clumsy. Therefore I thought of wrapping image.php into a function, and bundling it to my content page with include_once "image.php".

The strategy, however, produces the dreaded "Cannot modify header information" error. I believe this is because there is already output on the page, before the img is referenced. Does that mean that it is impossible to output an image src by function rather than by GET a separate file?

1
It's not completely impossible, but it's inadvisable for many reasons. But you could store all the parameters in a session variable, for example.Pekka

1 Answers

1
votes

This will not work because you are sending two different types of contents in one response, one is text/html and the other for example image/jpeg. Here is my suggestion: have a function that accepts all the arguments you need to render the image and have this function save it somewhere on the disk (cache/images for example) the function should then return the path to this image so you can put it in you src.