Here is a sample script. The table name is TBLFILESTORAGE. The upload component used is ASPUpload.
'getting uploaded files
dim obj_upload
Set obj_upload = Server.CreateObject("Persits.Upload.1")
obj_upload.OverwriteFiles = true
dim i_count ' the number of files uploaded
i_count = obj_upload.Save(Server.MapPath(".") & "\uploadedfiles")
if(i_count<1) then
Response.Write("No file is uploaded or the uploaded file is empty.")
end if
'saving files to db
dim i_loop
dim rst_file_storage
dim obj_file
For i_loop = 1 to i_count
'add file to db
Set obj_file = obj_upload.Files(i_loop)
dim file_content
file_content = obj_file.Binary
If Not obj_file Is Nothing Then ' If file is not enpty
Set rst_file_storage = Server.CreateObject("adodb.recordset")
rst_file_storage.Open "SELECT * FROM TBLFILESTORAGE", cnn_sql_blob, 2, 3
rst_file_storage.AddNew
rst_file_storage("file_name").Value = obj_file.Name
rst_file_storage("file_size").Value = obj_file.Size
rst_file_storage("file_content_type").Value = obj_file.ContentType
rst_file_storage("file_content").Value = obj_file.Binary
rst_file_storage.Update
rst_file_storage.close
set rst_file_storage = nothing
Response.Write("Successfully stored " & cstr(i_count) & " file(s) in DB.")
else
Response.Write("The file was not selected or it was empty")
end if
next
----------------------------------------------------------
The field file_storage is of type image.
The above is for SQL 2000.
Here is the script to create db table.
qry_createtable="CREATE TABLE [TBLFILESTORAGE]("&_
"[file_id] INT IDENTITY,"&_
"[file_name] VARCHAR(250),"&_
"[file_content_type] VARCHAR(1000),"&_
"[file_size] INT,"&_
"[file_content] IMAGE)"
cnn_sql_blob.Execute qry_createtable
|