狂抓吐血,200分紧急求助!(200分)

  • 主题发起人 主题发起人 lmk
  • 开始时间 开始时间
L

lmk

Unregistered / Unconfirmed
GUEST, unregistred user!
本人是个Delphi菜鸟,对ASP一窍不通!但最近帮一mm做毕业设计,用的就是ASP+ACCESS。
最近在网上找到了一段文件上传的代码,但发现此代码大部分格式的文件都不能上传上去,而且上传上的东西大部分都打不开,麻烦哪为大哥帮看看,代码如下:
'UPLOAD.HTM
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot;
Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE>文件上载</TITLE>
</HEAD>
<BODY>
<FORM METHOD=&quot;POST&quot;
ENCTYPE=&quot;multipart/form-data&quot;
ACTION=&quot;uploadexmple.asp&quot;>
<TABLE BORDER=0>
<tr><td><b>选取所要上载的文件:</b>
<INPUT TYPE=FILE NAME=&quot;FILE1&quot;>
<INPUT TYPE=SUBMIT VALUE=&quot;上载&quot;></td></tr>
</TABLE>
</FORM>
</BODY>
</HTML>
----------------------
'uploadexmple.asp
<%@ Language=VBScript %>
<%Option Explicit%>
<html>
<title>
文件上载
</title>
<body>
<!-- #include file=&quot;upload.asp&quot;
-->
<%
Dim Uploader, File
Set Uploader = New FileUploader
on error resume next
Uploader.Upload()
uploader.File.SaveToDisk &quot;e:/&quot;
if err.number=0 then
Response.Write &quot;<center><b>祝贺你已经成功上载了&quot;
& Uploader.File.FileName & &quot;文件</b><br></center><hr>&quot;
Response.Write &quot;<table align=center border=0>&quot;
Response.Write &quot;<tr><td><font color=red>文件名称:</font></td><td> &quot;
Response.Write Uploader.File.FileName & &quot;</td></tr>&quot;
Response.Write &quot;<tr><td><font color=red>文件大小:</font></td><td> &quot;
Response.Write Uploader.File.FileSize & &quot;
bytes</td></tr>&quot;
Response.Write &quot;<tr><td><font color=red>文件类型:</font></td><td> &quot;
Response.Write Uploader.File.ContentType & &quot;</td></tr>&quot;
end if
%>
</body>
</html>
----------------------
'upload.asp
<%
Class FileUploader
Public File
Private Sub Class_Initialize()
Set File = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
End Sub
Private Sub Class_Terminate()
set File=nothing
End Sub
Public Property Get Form(sIndex)
Form = &quot;&quot;
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(&quot;--&quot;))
nPos = InstrB(nDataBoundPos, biData, CByteString(&quot;Content-Disposition&quot;))
nPos = InstrB(nPos, biData, CByteString(&quot;name=&quot;))
nPosbegin
= nPos + 6
nPosEnd = InstrB(nPosbegin
, biData, CByteString(Chr(34)))
sInputName = CWideString(MidB(biData, nPosbegin
, nPosEnd-nPosbegin
))
nPosFile = InstrB(nDataBoundPos, biData, CByteString(&quot;filename=&quot;))
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, &quot;/&quot;))
nPos = InstrB(nPosEnd, biData, CByteString(&quot;Content-Type:&quot;))
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 =&quot;&quot;
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 = &quot;&quot;
Or FileName = &quot;&quot;
then
Exit Sub
If Mid(sPath, Len(sPath)) <> &quot;/&quot;
then
sPath = sPath & &quot;/&quot;
Set oFS = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
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
%>
 
哪位大哥有现成代码的能给小弟个啊!就是将文件转存在服务器指定文件夹的!
 
留个邮箱,回家帮你找找,以前有做过。
 
JSP的还能帮你,ASP的就不会了。
 
多谢楼上2位大哥,我已经搞定了,不过把对自己的要求降低了,无组件上传自己写不出,就用了第三方控件(脸红哈子)。
我的MSN:lmk_2000_1@126.com希望能多多指教!
 
多人接受答案了。
 
后退
顶部