« One Thousand Posts and still going strong | Main | Meet the neighbours »

December 19, 2006

.pdf files - upload via PHP, store in MySQL, retrieve

There's a common requirement to manage binary data - upload from a user, store, bring back in a web page. And where you have a substantial number of pieces of data - a lot of .pdf documents, .jpg or .gif images, or even Word documents, you'll wish to store them in a database with the potential for keyword and title fields to help in your indexing, and for efficiency of data structure.

Forms can easily be written to upload binary files - although you do need to remember to set the encoding type. PHP can handle the received data and put it to an SQL database ... and can front the retreival too. The code is short in each case, but I wouldn't say it's simple - you need to understand a lot of what's going on. If you would like to look at my scripts to learn from them ... they're available:

Upload form
Script to store uploaded .pdf to a database
Script to return latest .pdf for you to view

You're even welcome to try out the scripts - upload form which runs the store script when submitted and retreive latest .pdf.

Note - (a) This will also work with .jpg and .gif files if you change the header call in the pdfget script. (b) Please be careful what you upload in our test script - until another upload is done, the world can read it. (c) We offer an alternative image upload example here with more useful tips on binary data upload and handling.

Posted by gje at December 19, 2006 11:26 PM

Comments

Post a comment




Remember Me?


Well House Consultants Ltd. Copyright 2008