Login | Register  

Uploading Images to Database Using Persist AspUpload

by Scud   Tuesday, July 03, 2007 Rating:
 Vote this news:


You can upload your  images to MS-SQL server with this simple script. To upload a picture to sql database, be sure Persist AspUpoad installed in you server.  

Run create_image_table.sql on your sql server. This database holds some information about your image : size of image, width and  height of image. 

create_image_table.sql

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[article_images]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[article_images]
GO

CREATE TABLE [dbo].[article_images] (
[ImageID] [int] IDENTITY (1, 1) NOT NULL ,
[imgFile] [image] NULL ,
[imgType] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[imgSize] [int] NULL ,
[imgWidth] [int] NULL ,
[imgHeight] [int] NULL ,
[imgName] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

upload.asp

<html>
<head>
<title>Upload Image</title>
</head>
<body>
<form method="POST" action="save.asp" ENCTYPE="multipart/form-data" >
<p><input type="file" name="fldImage" size="25">
<input type="submit" value="Upload !" name="func"></p>
</form>
</body></html>

save.asp

<%
Set Upload = Server.CreateObject("Persits.Upload")
Upload.SetMaxSize 100000, True
Count = Upload.Save
Set File = Upload.Files("fldImage")
strCon = "Provider=SQLOLEDB;Server=LOCAL;UID=sa;PWD=;Database=articles;"
Set objRec = Server.CreateObject ("ADODB.Recordset")
objRec.Open "article_images", strCon, 2, 3
objRec.AddNew
objRec("imgFile") = File.Binary
objRec("imgType") = File.ImageType
objRec("imgSize") = File.Size
objRec("imgWidth") = File.ImageWidth
objRec("imgHeight") = File.ImageHeight
objRec("imgName") = File.FileName
objRec.Update 
objRec.Close
Set objRec = Nothing
%>





Dotnetindex.com is listed with 411asp.net
Dotnetindex.com is listed with aspin.com
Dotnetindex.com is listed with jspin.com
PHP, ASP, .NET, JSP Resources, Reviews







page counter
Copyright © 2007 Powered by GNews Publisher Positive. All rights reserved. Contact Us - Load Time: 0.14 second(s)