idhttp上传文件到asp失败

guaiqiqi 2012-03-25 12:19:32
upload.htm

<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件上传</title>
</head>

<body>
<form method="POST" action="SaveFile.asp">
文件上传:<input type="file" name="file" size="42"> <input type="submit" value="提交" name="bb">
</form>

</body>

</html>




SaveFile.asp
<%
dim file,filename,houzui
file = Request.Form("file")

if file="" then
response.write"<script>alert('请选择要上传的文件!');window.location.href='upload.htm';</script>"
else
houzui=mid(file,InStrRev(file, "."))

if houzui=".jpg" then '允许上传的文件类型
' filename=year(date) & month(date) & day(date) & Hour(time) & minute(time) & second(time) & houzui
filename= "kkk.jpg"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile file
objStream.SaveToFile Server.MapPath(filename),2
objStream.Close



' response.write"<script>alert('图片上传成功!');window.location.href='upload.htm';</script>"
else
' response.write"<script>alert('不允许上传" & houzui & "的格式!');window.location.href='upload.htm';</script>"
end if
end if





procedure TForm1.Button5Click(Sender: TObject);
var
res : String;
ms : TIdMultiPartFormDataStream;
h: TIdhttp;
f:string;
begin
if Opendialog1.Execute then
f:=Opendialog1.FileName;
if f='' then exit;
try
ms := TIdMultiPartFormDataStream.Create;
h := Tidhttp.Create(nil);
ms.AddFile('file',f,'');
idhttp1.Request.ContentType :='multipart/form-data' ;
res:=h.Post('http://127.0.0.1/SaveFile.asp',ms);
if res='上传成功' then
Application.MessageBox('图片上传成功!','提示',MB_OK+MB_ICONASTERISK)
else
Application.MessageBox('图片上传失败!','ERROR',MB_OK+MB_ICONSTOP);
finally
ms.Free;
end;

end;
...全文
93 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
kaikai_kk 2012-03-26
  • 打赏
  • 举报
回复
基本没有错,就是这么提交的,但if res='上传成功' then
不能这么判断,这里res的返回结果是response.write后面双引号中间的内容
山东蓝鸟贵薪 2012-03-25
  • 打赏
  • 举报
回复
不太清楚,帮你顶顶

1,594

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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