How to Store PDF Files in a Database

by Cristina Puno

Databases are used to store information for easy lookup and better data management. The usual types of data stored are texts and numbers. Data types such as VAR or VARCHAR will let you store characters or text, while INT and FLOAT will let you store numbers. One data type called a BLOB (binary large object) will enable you to store binary files such as a DOC file, executable files and PDF files. By creating an upload form connected to your database, you can successfully store PDF files in it.

1

Create a database to hold your PDF file. Create a new table to store a PDF file, with fields for the file name and a field to store the PDF file. Choose the BLOB data type for PDF storage; this will allow you to store binary data such as PDFs in your database.

2

Create an input form for users to upload the PDF on your database. Using Notepad or an HTML Editing tool such as Dreamweaver or FrontPage, create a form that has an input text field for the file, a "Browse" button for users to choose a PDF to upload and a "Submit" button to upload the file. In the <form> tag, specify a the file name of the upload script that will store the PDF file in your database. Save your form as an HTML file.

3

Create your upload script. Using a web programming language such as PHP or ASP.net, create a routine for handling the PDF file submitted. The script will have three sections: a database-connection script, a script to capture the data submitted by the form and the SQL that uploads the file in your database. Save your file. Make sure that the name of the file matches the one you indicated in your HTML form.

4

Upload the form and the script file on your web server.

5

Access the form and use it to upload your PDF file to the database.

Video of the Day

Brought to you by Techwalla
Brought to you by Techwalla

Items you will need

About the Author

Cristina Puno started writing in 2007 as a freelance web content manager and technical writer. She writes regularly for several online publications, including her own music website, The Indie Music Database. Puno holds a Master of Science in information management from Ateneo de Manila University.

More Articles

Photo Credits