文件上传的问题

飞天鼠 2006-04-29 10:50:24
大家好,小弟刚刚学写文件上传的程序,在网上看了一些资料,写了个简单的,如下:

<%
filePath = request.form("file")
fileName = binaryToString(filePath)
fileName = getFileName(fileName)
set objStream = server.createobject("adodb.stream")
objStream.type = 2
objStream.mode = 3

objStream.open
objStream.LoadFromFile filePath
objStream.saveToFile server.mappath(fileName),1

objStream.close
set objStream = nothing

function getFileName(filePath)
getFileName = Mid(filePath,InStrRev(filePath,"\")+1)
end function
%>

运行时出现以下提示:

ADODB.Stream (0x800A0BB9)
参数类型不正确,或不在可以接受的范围之内,或与其他参数冲突。

指示的错误是这句:objStream.LoadFromFile filePath

请问应该如何解决,为什么?
谢谢!
...全文
165 4 打赏 收藏 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
飞天鼠 2006-04-29
  • 打赏
  • 举报
回复
谢谢,不过我现在要的是应该怎样解决,而不是要已经可以用的代码。
liujiayu10 2006-04-29
  • 打赏
  • 举报
回复
<!--#include file="upload_class.asp"-->
<%
dim Msg,strJS,FileExt,DialogType,UpFileType,arrUpFileType,ranNum,FileName
dim FoundErr,EnableUpload
const Savepath="upload/"
const MaxFileSize=102400
const UpFileType_pic=".jpg|.gif|.bmp|.png"
const UpFileType_flash=".swf"
Msg=""
FoundErr=false
EnableUpload=false
%>
<html>
<head>
<title>上传文件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="html_edit.css">
</head>
<body leftmargin="2" topmargin="5" marginwidth="0" marginheight="0">
</body>
</html>
<%
set upload=new upload_DaYu
set File1=upload.file("FileName")
if File1.FileSize>(MaxFileSize*1024) then
Msg="文件大小超过了限制,最大只能上传" & CStr(MaxFileSize) & "K的文件!"
FoundErr=True
end if

FileExt=lcase(right(File1.filename,4))
DialogType=trim(upload.form("DialogType"))
select case DialogType
case "pic"
UpFileType=UpFileType_pic
case "flash"
UpFileType=UpFileType_flash
case else
UpFileType=""
end select

arrUpFileType=split(UpFileType,"|")
for i=0 to ubound(arrUpFileType)
if fileExt=trim(arrUpFileType(i)) then
EnableUpload=true
exit for
end if
next
if fileExt=".asp" or fileExt=".asa" or fileExt=".aspx" then
EnableUpload=false
end if
if EnableUpload=false then
Msg="这种文件类型不允许上传!\n只允许上传这几种文件类型:" & UpFileType
FoundErr=true
end if

strJS="<SCRIPT language=javascript>" & vbcrlf
if not FoundErr=true then
ranNum=int(900*rnd)+100
FileName=SavePath & year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&fileExt
File1.SaveAs Server.mappath("../"& FileName)
response.write "文件上传成功!"
strJS=strJS & "parent.document.form1.url.value='" & FileName & "';" & vbcrlf
else
strJS=strJS & "alert('" & Msg & "');" & vbcrlf
strJS=strJS & "window.location='Upload_Dialog.asp?DialogType=" & DialogType & "';" & vbcrlf
end if
strJS=strJS & "</script>" & vbcrlf
response.write strJS

set File1=nothing
set upload=nothing
%>
飞天鼠 2006-04-29
  • 打赏
  • 举报
回复
权限?请问是不是在IIS里设置,我不知道具体在里面哪里设置,请说详细点行吗?
谢谢!
邦迪代驾 2006-04-29
  • 打赏
  • 举报
回复
权限问题,换个路径

28,402

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧