L
lmk
Unregistered / Unconfirmed
GUEST, unregistred user!
本人是个Delphi菜鸟,对ASP一窍不通!但最近帮一mm做毕业设计,用的就是ASP+ACCESS。
最近在网上找到了一段文件上传的代码,但发现此代码大部分格式的文件都不能上传上去,而且上传上的东西大部分都打不开,麻烦哪为大哥帮看看,代码如下:
'UPLOAD.HTM
<HTML>
<HEAD>
<META NAME="GENERATOR"
Content="Microsoft Visual Studio 6.0">
<TITLE>文件上载</TITLE>
</HEAD>
<BODY>
<FORM METHOD="POST"
ENCTYPE="multipart/form-data"
ACTION="uploadexmple.asp">
<TABLE BORDER=0>
<tr><td><b>选取所要上载的文件:</b>
<INPUT TYPE=FILE NAME="FILE1">
<INPUT TYPE=SUBMIT VALUE="上载"></td></tr>
</TABLE>
</FORM>
</BODY>
</HTML>
----------------------
'uploadexmple.asp
<%@ Language=VBScript %>
<%Option Explicit%>
<html>
<title>
文件上载
</title>
<body>
<!-- #include file="upload.asp"
-->
<%
Dim Uploader, File
Set Uploader = New FileUploader
on error resume next
Uploader.Upload()
uploader.File.SaveToDisk "e:/"
if err.number=0 then
Response.Write "<center><b>祝贺你已经成功上载了"
& Uploader.File.FileName & "文件</b><br></center><hr>"
Response.Write "<table align=center border=0>"
Response.Write "<tr><td><font color=red>文件名称:</font></td><td> "
Response.Write Uploader.File.FileName & "</td></tr>"
Response.Write "<tr><td><font color=red>文件大小:</font></td><td> "
Response.Write Uploader.File.FileSize & "
bytes</td></tr>"
Response.Write "<tr><td><font color=red>文件类型:</font></td><td> "
Response.Write Uploader.File.ContentType & "</td></tr>"
end if
%>
</body>
</html>
----------------------
'upload.asp
<%
Class FileUploader
Public File
Private Sub Class_Initialize()
Set File = Server.CreateObject("Scripting.FileSystemObject"
End Sub
Private Sub Class_Terminate()
set File=nothing
End Sub
Public Property Get Form(sIndex)
Form = ""
End Property
Public Default Sub Upload()
Dim biData, sInputName
Dim nPosbegin
, nPosEnd, nPos, vDataBounds, nDataBoundPos
Dim nPosFile, nPosBound
biData = Request.BinaryRead(Request.TotalBytes)
nPosbegin
= 1
nPosEnd = InstrB(nPosbegin
, biData, CByteString(Chr(13)))
If (nPosEnd-nPosbegin
) <= 0 then
Exit Sub
vDataBounds = MidB(biData, nPosbegin
, nPosEnd-nPosbegin
)
nDataBoundPos = InstrB(1, biData, vDataBounds)
do
Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--")
nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition")
nPos = InstrB(nPos, biData, CByteString("name=")
nPosbegin
= nPos + 6
nPosEnd = InstrB(nPosbegin
, biData, CByteString(Chr(34)))
sInputName = CWideString(MidB(biData, nPosbegin
, nPosEnd-nPosbegin
))
nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename=")
nPosBound = InstrB(nPosEnd, biData, vDataBounds)
If nPosFile <> 0 And nPosFile < nPosBound then
Dim oUploadFile, sFileName
Set oUploadFile = New UploadedFile
nPosbegin
= nPosFile + 10
nPosEnd = InstrB(nPosbegin
, biData, CByteString(Chr(34)))
sFileName = CWideString(MidB(biData, nPosbegin
, nPosEnd-nPosbegin
))
oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "/")
nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:")
nPosbegin
= nPos + 14
nPosEnd = InstrB(nPosbegin
, biData, CByteString(Chr(13)))
oUploadFile.ContentType = CWideString(MidB(biData, nPosbegin
, nPosEnd-nPosbegin
))
nPosbegin
= nPosEnd+4
nPosEnd = InstrB(nPosbegin
, biData, vDataBounds) - 2
oUploadFile.FileData = MidB(biData, nPosbegin
, nPosEnd-nPosbegin
)
set File=oUploadFile
else
nPos = InstrB(nPos, biData, CByteString(Chr(13)))
nPosbegin
= nPos + 4
nPosEnd = InstrB(nPosbegin
, biData, vDataBounds) - 2
End If
nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
Loop
End Sub
Private Function CByteString(sString)
Dim nIndex
For nIndex = 1 to Len(sString)
CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
Next
End Function
Private Function CWideString(bsString)
Dim nIndex
CWideString =""
For nIndex = 1 to LenB(bsString)
CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1)))
Next
End Function
End Class
Class UploadedFile
Public ContentType
Public FileName
Public FileData
Public Property Get FileSize()
FileSize = LenB(FileData)
End Property
Public Sub SaveToDisk(sPath)
Dim oFS, oFile
Dim nIndex
If sPath = ""
Or FileName = ""
then
Exit Sub
If Mid(sPath, Len(sPath)) <> "/"
then
sPath = sPath & "/"
Set oFS = Server.CreateObject("Scripting.FileSystemObject"
If Not oFS.FolderExists(sPath) then
Exit Sub
Set oFile = oFS.CreateTextFile(sPath & FileName, True)
For nIndex = 1 to LenB(FileData)
oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
Next
oFile.Close
End Sub
End Class
%>
最近在网上找到了一段文件上传的代码,但发现此代码大部分格式的文件都不能上传上去,而且上传上的东西大部分都打不开,麻烦哪为大哥帮看看,代码如下:
'UPLOAD.HTM
<HTML>
<HEAD>
<META NAME="GENERATOR"
Content="Microsoft Visual Studio 6.0">
<TITLE>文件上载</TITLE>
</HEAD>
<BODY>
<FORM METHOD="POST"
ENCTYPE="multipart/form-data"
ACTION="uploadexmple.asp">
<TABLE BORDER=0>
<tr><td><b>选取所要上载的文件:</b>
<INPUT TYPE=FILE NAME="FILE1">
<INPUT TYPE=SUBMIT VALUE="上载"></td></tr>
</TABLE>
</FORM>
</BODY>
</HTML>
----------------------
'uploadexmple.asp
<%@ Language=VBScript %>
<%Option Explicit%>
<html>
<title>
文件上载
</title>
<body>
<!-- #include file="upload.asp"
-->
<%
Dim Uploader, File
Set Uploader = New FileUploader
on error resume next
Uploader.Upload()
uploader.File.SaveToDisk "e:/"
if err.number=0 then
Response.Write "<center><b>祝贺你已经成功上载了"
& Uploader.File.FileName & "文件</b><br></center><hr>"
Response.Write "<table align=center border=0>"
Response.Write "<tr><td><font color=red>文件名称:</font></td><td> "
Response.Write Uploader.File.FileName & "</td></tr>"
Response.Write "<tr><td><font color=red>文件大小:</font></td><td> "
Response.Write Uploader.File.FileSize & "
bytes</td></tr>"
Response.Write "<tr><td><font color=red>文件类型:</font></td><td> "
Response.Write Uploader.File.ContentType & "</td></tr>"
end if
%>
</body>
</html>
----------------------
'upload.asp
<%
Class FileUploader
Public File
Private Sub Class_Initialize()
Set File = Server.CreateObject("Scripting.FileSystemObject"
End Sub
Private Sub Class_Terminate()
set File=nothing
End Sub
Public Property Get Form(sIndex)
Form = ""
End Property
Public Default Sub Upload()
Dim biData, sInputName
Dim nPosbegin
, nPosEnd, nPos, vDataBounds, nDataBoundPos
Dim nPosFile, nPosBound
biData = Request.BinaryRead(Request.TotalBytes)
nPosbegin
= 1
nPosEnd = InstrB(nPosbegin
, biData, CByteString(Chr(13)))
If (nPosEnd-nPosbegin
) <= 0 then
Exit Sub
vDataBounds = MidB(biData, nPosbegin
, nPosEnd-nPosbegin
)
nDataBoundPos = InstrB(1, biData, vDataBounds)
do
Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--")
nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition")
nPos = InstrB(nPos, biData, CByteString("name=")
nPosbegin
= nPos + 6
nPosEnd = InstrB(nPosbegin
, biData, CByteString(Chr(34)))
sInputName = CWideString(MidB(biData, nPosbegin
, nPosEnd-nPosbegin
))
nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename=")
nPosBound = InstrB(nPosEnd, biData, vDataBounds)
If nPosFile <> 0 And nPosFile < nPosBound then
Dim oUploadFile, sFileName
Set oUploadFile = New UploadedFile
nPosbegin
= nPosFile + 10
nPosEnd = InstrB(nPosbegin
, biData, CByteString(Chr(34)))
sFileName = CWideString(MidB(biData, nPosbegin
, nPosEnd-nPosbegin
))
oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "/")
nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:")
nPosbegin
= nPos + 14
nPosEnd = InstrB(nPosbegin
, biData, CByteString(Chr(13)))
oUploadFile.ContentType = CWideString(MidB(biData, nPosbegin
, nPosEnd-nPosbegin
))
nPosbegin
= nPosEnd+4
nPosEnd = InstrB(nPosbegin
, biData, vDataBounds) - 2
oUploadFile.FileData = MidB(biData, nPosbegin
, nPosEnd-nPosbegin
)
set File=oUploadFile
else
nPos = InstrB(nPos, biData, CByteString(Chr(13)))
nPosbegin
= nPos + 4
nPosEnd = InstrB(nPosbegin
, biData, vDataBounds) - 2
End If
nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
Loop
End Sub
Private Function CByteString(sString)
Dim nIndex
For nIndex = 1 to Len(sString)
CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
Next
End Function
Private Function CWideString(bsString)
Dim nIndex
CWideString =""
For nIndex = 1 to LenB(bsString)
CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1)))
Next
End Function
End Class
Class UploadedFile
Public ContentType
Public FileName
Public FileData
Public Property Get FileSize()
FileSize = LenB(FileData)
End Property
Public Sub SaveToDisk(sPath)
Dim oFS, oFile
Dim nIndex
If sPath = ""
Or FileName = ""
then
Exit Sub
If Mid(sPath, Len(sPath)) <> "/"
then
sPath = sPath & "/"
Set oFS = Server.CreateObject("Scripting.FileSystemObject"
If Not oFS.FolderExists(sPath) then
Exit Sub
Set oFile = oFS.CreateTextFile(sPath & FileName, True)
For nIndex = 1 to LenB(FileData)
oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
Next
oFile.Close
End Sub
End Class
%>