1.asp怎么实现存入数据库
2.ç¨ASP.NETå建ç½ç»ç¸åä¿åç¾ä¸½è®°å¿
asp怎么实现存入数据库
上传到放的册源册获文件夹,数据库中只用放相对路径。码相码设备软件源码阅读
一般无组件上传用
upload_5xsoft.inc文件:
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
dim upfile_5xSoft_Stream
Class upload_5xSoft
dim Form,取源安卓模拟操作源码File,Version
Private Sub Class_Initialize
dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version="gt.com上传程序v1.0"
if Request.TotalBytes<1 then Exit Sub
set Form=CreateObject("Scripting.Dictionary")
set File=CreateObject("Scripting.Dictionary")
set upfile_5xSoft_Stream=CreateObject("Adodb.Stream")
upfile_5xSoft_Stream.mode=3
upfile_5xSoft_Stream.type=1
upfile_5xSoft_Stream.open
upfile_5xSoft_Stream.write Request.BinaryRead(Request.TotalBytes)
vbEnter=Chr()&Chr()
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
while iFormStart < iFormEnd
iStart=inString(iFormStart,"name=""")
iEnd=inString(iStart+6,"""")
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,"filename=""")
if iFileNameStart>0 and iFileNameStart<iFormEnd then
iFileNameEnd=inString(iFileNameStart+,"""")
mFileName=subString(iFileNameStart+,iFileNameEnd-iFileNameStart-)
iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
if iEnd>iStart then
mFileSize=iEnd-iStart-4
else
mFileSize=0
end if
set theFile=new FileInfo
theFile.FileName=getFileName(mFileName)
theFile.FilePath=getFilePath(mFileName)
theFile.FileSize=mFileSize
theFile.FileStart=iStart+4
theFile.FormName=FormName
file.add mFormName,theFile
else
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
if iEnd>iStart then
mFormValue=subString(iStart+4,iEnd-iStart-4)
else
mFormValue=""
end if
form.Add mFormName,mFormValue
end if
iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
wend
End Sub
Private Function subString(theStart,theLen)
dim i,c,stemp
upfile_5xSoft_Stream.Position=theStart-1
stemp=""
for i=1 to theLen
if upfile_5xSoft_Stream.EOS then Exit for
c=ascB(upfile_5xSoft_Stream.Read(1))
If c > Then
if upfile_5xSoft_Stream.EOS then Exit for
stemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))
i=i+1
else
stemp=stemp&Chr(c)
End If
Next
subString=stemp
End function
Private Function inString(theStart,varStr)
dim i,j,bt,theLen,str
InString=0
Str=toByte(varStr)
theLen=LenB(Str)
for i=theStart to upfile_5xSoft_Stream.Size-theLen
if i>upfile_5xSoft_Stream.size then exit Function
upfile_5xSoft_Stream.Position=i-1
if AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1)) then
InString=i
for j=2 to theLen
if upfile_5xSoft_Stream.EOS then
inString=0
Exit for
end if
if AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
InString=0
Exit For
end if
next
if InString<>0 then Exit Function
end if
next
End Function
Private Sub Class_Terminate
form.RemoveAll
file.RemoveAll
set form=nothing
set file=nothing
upfile_5xSoft_Stream.close
set upfile_5xSoft_Stream=nothing
End Sub
Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function
Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function
Private function toByte(Str)
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode<0 Then iCode = iCode +
If iCode> Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function
End Class
Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
End Sub
Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=1
if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
if FileStart=0 or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=0
end function
End Class
</SCRIPT>
调用样式:
<!--#include file="conn.asp" -->
<!--#include file="upload_5xsoft.inc" -->
<%
if request("action")="addpic" then
set upload=new upload_5xSoft
set file=upload.file("file1")
formPath="../xiangce/"
formpath1="xiangce/"
if file.filesize> then
fileExt=lcase(right(file.filename,3))
if fileExt="asp" then
Response.Write"文件类型非法"
end if
end if
randomize
ranNum=int(*rnd)+
filename0=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
filename=formPath&filename0
filename1=formpath1&filename0
if file.FileSize>0 then
file.SaveAs Server.mappath(FileName)
end if
response.write "上传成功,[<a href='picture.asp?pic_url="&filename1&"'>返回填写名称和主题</a>]"
else
set upload=new upload_5xSoft
set file=upload.file("file1")
formPath="newimage/"
if file.filesize> then
fileExt=lcase(right(file.filename,3))
if fileExt="asp" then
Response.Write"文件类型非法"
end if
end if
randomize
ranNum=int(*rnd)+
filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
if file.FileSize>0 then
file.SaveAs Server.mappath(FileName)
end if
response.write "上传成功"
end if
%>
传值的表单用文件类型。
ç¨ASP.NETå建ç½ç»ç¸åä¿åç¾ä¸½è®°å¿
ããå¨æ们çæ¥å¸¸çæ´»ä¸æ°ç ç §å设å¤å·²ç»å¾æ®éäº æ们ä¼ç»å¸¸ææä¸äºç¸ç以ä¾ç念 èéçæ°ç ç §ççå¢å¤ å¾å¾éè¦å¾å¥½å°ç®¡çè¿äºç §ç 以便æ´å¥½å°æ¥é ç念 ç°å¨ç½ä¸æä¸å°ççµåç¸å é½è½å¾å¥½çå®ç°è¿äºåè½ é£æ们è½å¦èªå·±å¨æå建èªå·±çç¸åå¢ï¼å½ç¶å¯ä»¥ å¨è¿ç¯æç« ä¸ æ们å°å©ç¨asp net æ¥å建ä¸ä¸ªç®åçå¨çº¿ç¸å 以æ¶èæ们çç §çããé¦å æ¥çä¸ è¿ä¸ªç¸åæåªäºåè½ å¨è¿ä¸ªç¸åä¸ æä»¬å¿ é¡»å æé¢å æ影好çç §çæ¾å°ä¸ä¸ªç®å½ä¸å» ä¹å å¯ä»¥ä¾å¨ç½ä¸ä½¿ç¨ ä¸ä¸å¼ ä¸ä¸å¼ çé¾æ¥ä¸å¼ å¼ å°æ¥ç
ããä¸é¢å ä»ç»å¦ä½è·å¾æ件夹ä¸çå¾ç æ们å¯ä»¥ä½¿ç¨System IOå½å空é´ä¸çDirectoryInfoç±»æ¥å®ç° å°æ件夹æå¨çè·¯å¾å为åæ°ä¼ éå°è¯¥ç±»çæé å½æ°ä¸ 并声æä¸ä¸ªDirectoryInfoç±»çå®ä¾ DirectoryInfoç±»ä¸æä¸ä¸ªGetFiles()çæ¹æ³ ä¼è¿åFileInfoç对象æ°ç» èæ¯ä¸ä¸ªFileInfoçå®ä¾å°å å«æå®è·¯å¾ä¸æ件çå ·ä½ä¿¡æ¯ ä¸é¢ç代ç ç段说æäºè¯¥è¿ç¨
ãã以ä¸ä¸ºå¼ç¨çå 容 Sub Page_Load(sender as Object e as EventArgs)ã Get list of imagesãDim dirInfo as New DirectoryInfo(Server MapPath( ))ãDim images() as FileInfo = FilterForImages(dirInfo GetFiles())ã End Subããå ¶ä¸ ç¨Server mappathè·å¾å½åç®å½çè·¯å¾ èdirinfo getfiles()å°ä¼è¿å该ç®å½ä¸çæææ件 èç±äºæ们çæ¯ç¸å åªéè¦çå°æ¯å¦JPG BMP GIFçå¾è±¡æ件 æ以æ们å¯ä»¥éè¿ç¨åºå®ç° åªè£ è½½è¿äºç±»åçæ件 è¿éè¿ä¸ä¸ªèªå®ä¹çè¿ç¨FilterForImagesæ¥å®ç° 该è¿ç¨å°åªè¿åæå®æ件夹ä¸å¾è±¡ç±»åçæ件 代ç å¦ä¸
以ä¸ä¸ºå¼ç¨çå 容 Function FilterForImages(images() as FileInfo) as FileInfo()ãDim newImages as New ArrayList(images Length)
ãDim i as IntegerãFor i = to images Length ããIf Path GetExtension(images(i) Name) = jpg OrElse _ãããPath GetExtension(images(i) Name) = jpeg OrElse _ ãããPath GetExtension(images(i) Name) = png OrElse _ ãããPath GetExtension(images(i) Name) = gif thenããããnewImages Add(images(i))ããEnd IfãNext
ãReturn CType(newImages ToArray(GetType(FileInfo)) FileInfo())End Function
ãã该è¿ç¨å¯¹äºä¼ éè¿æ¥çFileInfoåæ°æ°ç»è¿è¡éå 对æ件夹ä¸çæ件çåç¼åè¿è¡åæ å¦æå±äºå¾è±¡æ件 åæ·»å å°newimagesæ°ç»ä¸å» 并以arraylistå½¢å¼è¿å
ããæ¥ä¸æ¥ æ们çä¸å¦ä½æ¾ç¤ºæ¯ä¸å¼ å¾ç 并以 ä¸ä¸å¼ ä¸ä¸å¼ æ¥æ¾ç¤º 为äºç¥éå½åæµè§çæ¯ç¬¬å å¼ å¾ç å¯ä»¥éè¿ä½¿ç¨ä¼ éåæ°çæ¹æ³æ¥å®ç° å å¾çªä½ä¸æ·»å ä¸ä¸ªimageæ§ä»¶åææ¬æ¡ ç¨åºä»£ç å¦ä¸
以ä¸ä¸ºå¼ç¨çå 容 Sub Page_Load(sender as Object e as EventArgs)ã
ã Dim imgIndex as Integer = ãIf Not Request QueryString( N ) is 册源册获mfc网络编程实例源码Nothing AndAlso _ããIsNumeric(Request QueryString( N )) thenãããimgIndex = CInt(Request QueryString( N ))ãEnd IfããcurrentImgTitle Text = You are Viewing: & _ããPath GetFileNameWithoutExtension(images(imgIndex) Name) & _ãã ( & imgIndex + & of & images Length & ) ãããcurrentImg ImageUrl = Path GetFileName(images(imgIndex) Name)ããã End Sub
ããHTMLé¨å代ç
以ä¸ä¸ºå¼ç¨çå 容 <asp:Label runat= server id= currentImgTitle /><br /><asp:Image runat= server id= currentImg /> lishixinzhi/Article/program/net//