user3824329
user3824329

Reputation: 95

Including image with header in php

What I am trying to achieve is to include an image with php. I am using the header png function:

header('Content-Type: image/png');

Then I am including the image by jusing the include() function.

Some images are returning correctly, but most of them around 90% give the same error. The error is this:

Parse error: syntax error, unexpected ' in algemeen.png on line 103

The strange thing is that I have exactly the same code running on an older server and there works everything fine. Every image is returned correctly. And I have exact the same copy of that old server running on this server, but then I recieve the errors shown above.

Does anyone know what I can do about it ?

Upvotes: 0

Views: 53

Answers (1)

toster-cx
toster-cx

Reputation: 2387

Use readfile

readfile("/path/to/file.png");

I'm guessing the binary data in the image accidentally contains <? or <?php tags that get executed as code when using include.

Upvotes: 2

Related Questions