Hi,
I've been a programmer for many years, but am new to PHP and almost all things related to web developement.
I know there's arguments both ways about storing images / PDF's etc in BLOB's, but it's what I've been tasked to do. I've read many posts and tried many variations of my code, but no matter how simple it looks, I just can't get it to work.
I have a very basic table named "pdf" with a field named "file_name" of type varchar and a field "pdf_file" of type longblob. The script connects to my db fine, inserts a new record, puts the file name in the appropriate field and puts [BLOB] in the pdf_file field. The pdf size is ~ 60 KB and after inserting 15 - 20 records, the db size (pdf table is only one in this test db) is 6K. So, the PDF ins't making it into the table.
Can anyone give me a clue to what I'm missing:
<?
if ($REQUEST_METHOD == "POST") {
$file_name="/1090/WD-D.pdf";
$instr = fopen($file_name,"rb");
$file_content = addslashes(fread($instr,filesize($file_name)));
$file_type = "application/pdf";
SQLQuery("mydb", $cid, "insert into pdf (file_name, pdf_file) VALUES('$file_name', $file_content')");
}
?>
And, assuming I get that to work, should I be able to display it (just for testing) by adding the following 3 lines to the above
header("Content-type: application/pdf");
echo $stmt_content;
exit ();
I assume the content type will fire up acrobat reader or open another window with the pdf in it or ???
Your help in getting me on course is appreciated.
David