After a several hours looking for this bug, I was socked and a bit upset to realize it was due to a espace character after ?>
tag in my php script.
The problem
I was simply trying to show a file that was storage in a BLOB table in a database using PHP. After investigating and isolating the problem, it seemed to be around these lines of code bellow.
problem.php
<?php
require_once('empty-script.php');
$data = file_get_contents('./images/download.jpeg');
header("Content-Type: image/jpeg");
echo $data;
?>
empty-script.php
<?php
?>
The Bug
Instead of getting an output, this was the outcome on the browser. Not desired.
Getting Nuts
At some point I decided to comment the require_once
. After noticing the bug was gone, I was about to blame it for the issue. Then it occurred me to create another empty file and import it.
The new empty file was working, require_once
not necessarily was the one to be blamed.
After a few minutes I noticed that there was an extra space after ?>
in empty-script.php
that was causing the image/file to not be rendered.
The Question
Is that a bug from PHP? Am I unaware of a documentation regarding this? Why this happens?
This is my server configuration