I'm storing files in a LONGBLOB field in MySQL. When I retrieve the file using PHP, it has one extra space at the beginning of the file. I have checked my blob data in the MySQL Workbench viewer, the extra space is not in the raw data. Every file I download has an extra space at the beginning. The space does not exist in the $file['file'] variable, I have written it to a log and checked. It gets added somewhere in the handoff between PHP and the browser.
Here's the PHP:
<?php
include("log.php");
$log = new log;
$dbserver='localhost';
$dbid='xxxx';
$dbpw='xxxx';
$dbname='xxxx';
$mydb=mysqli_connect($dbserver,$dbid,$dbpw);
mysqli_set_charset($mydb,'utf8');
mysqli_select_db($mydb, $dbname) or die($log->log("Unable to select database"));
$q = "SELECT * FROM files WHERE id=$fileID";
$r = mysqli_query($mydb, $q) or die ($log->log(mysqli_error($mydb) . $q));
$file = mysqli_fetch_array($r, MYSQLI_ASSOC);
header("Content-Type: {$file['fileType']}");
header("Content-Disposition: filename=\"{$file['fileName']}\"", true);
header("Content-Length: {$file['fileSize']}");
echo trim($file['file']);
?>
I have seen other people identify extra spaces on the PHP page or the BOM in UTF-8 encoding, but I can find nothing like that on my page.
I'm using Notepad++ and UTF-8 w/o BOM. I also tried creating a new file on the server using vim through a terminal and no change.
Trim doesn't help either.
I've used Notepad++ to "Show all characters" hoping to find that extra something somewhere and there does not appear to be any extra characters hiding in my file.
The PHP open carat is the first character of the file and the closing carat is the last character of the file.
What else can there be?
Thanks, Bernn