Hi,
I am trying to upload a pdf document into mySQL as a blob (using php). I have got the file going into the database no problem:
if(!empty($HTTP_POST_FILES["pdf"]['name']))
{
$pdf_name = $HTTP_POST_FILES['pdf']['name'];
$pdf_size = $HTTP_POST_FILES['pdf']['size'];
$pdf_type = $HTTP_POST_FILES['pdf']['type'];
$pdf_tmp = $HTTP_POST_FILES['pdf']['tmp_name'];
$file = fopen($pdf_tmp, "r");
if(!$file)
{
$pdfError = $pdfError."file did not work... ";
$contentOk=false;
} // end of check file works
else
{
// $pdfError = $pdfError."file did work... ";
$pdf = AddSlashes(fread($file, $pdf_size));
if(!$pdf)
{
$pdfError = $pdfError."fread did not work... ";
$contentOk=false;
} // end of check pdf works
else
{
$pdfOk = true;
} // end of pdf ok
} // end of file ok
} //end of organise pdf details
//Then go onto insert into the database table//
This all works as expected and inserts the binary data into the database.
The problem I am having is trying to get it back out again for display.
I have tried using:
$getPdfQuery = "select pdf, format from company where companyid ='{$id}'";
$getPdfResult = $connection->query($getPdfQuery);
while($getPdfRow = $getPdfResult->fetchRow(DB_FETCHMODE_ASSOC))
{
$pdf = $getPdfRow["pdf"];
//$format = $getPdfRow["format"];
}
header ("Content-type: application/pdf");
echo $pdf;
However, when I run this code, I get an Acrobat warning:
"The file is damaged and could not be repaired"
Any ideas?