Uploading Files into an Access Database using plain ASP by Faisal Khan.
Introduction
In this tutorial you are going to learn everything in detail step by step you'll
ever want to know about inserting binary data ( images, zip files etc ) into database.
This is actually first of the three articles I am going to write on manipulating binary
data in the database. After this article you'll be able to upload binary data into
database, then in the second article (Displaying Images from an Access Database using plain ASP) you'll learn to get this data out of database and display
it as you like. Finally in the third article (Uploading Files to the Server Hard Disk using plain ASP) I'll explain uploading files. All of this
is going to be plain ASP ( VBScript ) and nothing else, so stay tuned.
File Uploading with ASP.NET
If you have the privilege of using ASP.NET then you should read these comprehensive tutorials regarding file uploading using built-in ASP.NET server controls:
- File uploading
to server hard disk.
- File uploading to Microsoft Access database.
- Uploading images, determining size, width & height and resizing image files.
Requirements
You should be able to run ASP pages, this is all that is required. But due to older versions
of VBScript runtime on some systems, it is recommended that you download and install latest version
of VBScript runtime from here. If
you don't do this and get an error then download the latest runtime and it should work!
Why store binary data in database ?
Getting binary data in and out of databases is expensive, expensive in terms of server
resources and time it takes for it. But having said that it is very convenient and in some
cases extremely important to save all kind of data at a central place e.g, an ad server. You can then build
some custom ASP pages that retrieve data out of database and keep them in temporary folders
on the hard disk and display them when needed, then after some expiry time they
can refresh that file with new one from the database. Possibilities are endless.
What will you need ?
All we are going to use is plain simple ASP. The database that I've chosen is Microsoft
Access database. I could have explained it on Microsoft SQL Server but I chose Access
because it is inexpensive and widely available. Transition form Access to SQL Server is very easy.
Creating Access Database
Start Microsoft Access database and create a new database. Save it as 'FileDB.mdb'
in a safe folder. Now create a new table in design view and save it as 'Files'. The
structure of this table should look like following where 'ID' is the primary key :
Files - Table
Creating Loader class
Now open your note pad ( or any other ASP editor you use ) and create a new file.
Save it as 'Loader.asp'. Now copy the text listed below and paste it
in to the newly created 'Loader.asp' page and hit the save button :
|