<%@import namespace =namespace="system.data"%> <%'@import namespace="system.data.oledb"%> <!--access数据库用这个--> <%@import namespace =namespace="system.data.sqlclient"%> <!--sql server数据库用这个--> <script language="vb" runat="server"> sub uploadfile()sub uploadfile(sender as object, e as eventargs) dim fileext fileext = lcase(right(trim(fileup.value),3)) if fileext = "gif" or fileext = "jpg" or fileext = "bmp" or fileext = "png" or fileext = "tif" or lcase(right(trim(fileup.value),4)) = "jpeg" then if fileup.postedfile.contentlength = 0 then fileinfo.visible = false exit sub else fileinfo.visible = true end if
dim filesplit() as string = split( fileup.postedfile.filename, "/" ) dim filename as string = filesplit(filesplit.length-1) fileup.postedfile.saveas( server.mappath(".") & "/upload/" & filename )
'把文件路径写入数据库 by dicky 2005-7-12 9:26:29 ' access数据库用这个 ' dim objcommand as oledbcommand ' dim objconnection as oledbconnection ' objconnection = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source="+server.mappath("upload.mdb")) ' objcommand = new oledbcommand("insert into upload (filepath) values ('upload/"+filename+"')" , objconnection) ' access数据库用这个
' sql server数据库用这个 dim objcommand as sqlcommand dim objconnection as sqlconnection objconnection = new sqlconnection("server=localhost;uid=sa;pwd=;database=shat_edg") objcommand = new sqlcommand("insert into upload (filepath) values ('upload/"+filename+"')" , objconnection) ' sql server数据库用这个
objconnection.open() objcommand.executenonquery() objconnection.close() '把文件路径写入数据库 by dicky 2005-7-12 9:26:29
dim exts() as string = split( filename, "." ) dim ext as string = lcase(exts(exts.length-1)) if ext <> "jpg" and ext <> "jpeg" and ext <> "gif" and ext <> "txt" and ext <> "htm" and ext <> "html" then fdisplay.visible = false else fdisplay.text = "<a target='_blank' href='upload/" & _ filename & "'>上传文件</a>" end if response.write("上传成功!") else ' msgbox("对不起,只能上传扩展名为gif、jpg、bmp、png、tif或jpeg等图片文件!",65,"a") response.write("对不起,只能上传扩展名为gif、jpg、bmp、png、tif或jpeg等图片文件!") end if end sub </script>