How to store a PDF file in a MySQL database using PHP?
Using BLOB (Binary Large Object) (longblob
datatype)
$fileHandle = fopen($fileUpload, "r");
$fileContent = fread($fileHandle, $fileUpload_size);
$fileContent = addslashes($fileContent);
$dbQuery = "INSERT INTO myBlobs VALUES ";
$dbQuery .= "('$fileContent')";
The full tutorial available here
but it's strongly recommended to store files on the file system, and just add a reference in the DB (a field with the file path and name). Several reasons:
Use a type BLOB.
Here's an example in PHP
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With