I created a database that stores various data about an image as well as the image itself. I have five keys (id, name, size, format, file). The id is auto-incrementable. The file is a value of a BLOB type - (mediumblob). Rest is of its respective type. The weird thing is that every other variable is successfully written to the database except for the BLOB image itself.
Wait for the user to upload an image using $_POST:
if(isset($_POST['file_one_submit'])){
$post = 'file_one_input';
}
Define all the variables. Including the $file variable with:
$file = file_get_contents($_FILES[$post]['tmp_name']);
Then I make a query to replace the record in the database with the new information:
$stmt = $conn -> prepare("REPLACE INTO `images` (id, name, size, format, file) VALUES(?, ?, ?, ?, ?);");
$stmt -> bind_param("isisb", $id, $name, $size, $format, $file);
$stmt -> execute();
After the query's been executed all records in the database successfully get updated with the exception of the file column which should contain the BLOB data. I thought that the $post variable may be incorrectly defined but getting the name of the uploaded file for instance works:
upload_name = $_FILES[$post]['name'];
I've tried to echo the $file variable to check its contents and got presented with a long rubbish of data which I assume is the proper string generated during the conversion to BLOB with the file_get_contents() function.
I've checked that the size of the file does not exceed the capabilities of the mediumblob BLOB type. I've also attempted to check for errors in my code with this post without success. No errors or warnings appear on the page when the code is run. I've also enabled error/warning checks with E_STRICT but still, no output was presented.