So, I have a file on the file system of the same server on which the MySQL database resides. I thought that copying the file to the database should be pretty straight-forward, since, when uploading a file into a MySQL BLOB, all you're actually using is a file that's sitting in /tmp
So, here's the simplified code:
$file = '/path/to/my/file';
$f = fopen($file, 'r');
$data = mysql_escape_string(fread($f, filesize($file)));
mysql_query("INSERT INTO FilesTable SET Data = '{$data}'");
(The 'data' field is a longblob)
What always ends up happening is that the contents 'data' will be truncated to only the first five-or-so characters of the file. Yet, I can do the exact same thing with an uploaded file (using $_FILES['file']['tmp_name']) and it will work without a hitch.
Why doesn't this work? Am I missing something?