| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 599 人关注过本帖
标题:[求助] 修改代码 大侠请进
只看楼主 加入收藏
lnsyhsz
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-11-4
收藏
 问题点数:0 回复次数:4 
[求助] 修改代码 大侠请进

这个是 一个上传的asp 的代码 我想限制图片大小 50k以内



<%
Dim FormPath
FormPath = "TempUpload/" ''定义上传路径
Upload_0

Sub Upload_0()
Dim Upload
Dim File,FormName,FileName,FileExt,SaveFile
Dim CountSize,UseTime
CountSize = 0
Set Upload = Server.CreateObject("DvFile.Upload") ''建立上传对象
Upload.InceptFileType = "jpg,gif,png,bmp,jpeg" ''上传文件类型限制 以 “,” 号分隔
Upload.MaxSize = -1 ''限制大小 :-1为无限,单位 B
Upload.Install ''加载上传数据
If Upload.Err > 1 Then ''错误参数
''输出错误信息
Select Case Upload.Err
Case 1 : Response.Write Upload.Description ''请先选择你要上传的文件
Case 2 : Response.Write Upload.Description ''文件大小超过了限制 "&Upload.MaxSize/1024&"K 
Case 3 : Response.Write Upload.Description ''非法的上传类型
Case 4 : Response.Write Upload.Description ''所上传的类型受系统限制
Case 5 : Response.Write Upload.Description ''参数有误,上传意外中止
End Select
Response.Write " [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
Exit Sub
Else
'If Upload.Count>1 Then Response.Write "上传个数超过限制" : Exit Sub
'FormPath = Upload.Form("filepath") ''从表单filepath获取上传路径
For Each FormName In Upload.File ''列出所有上传了的文件
Set File = Upload.File(FormName) ''生成一个文件对象
FileExt = File.FileExt ''获取上传文件后缀名
FormPath = FormatPath(FormPath) ''格式化上传路径
FileName = FormatName(FileExt) ''定义文件名
SaveFile = FormPath & FileName
If File.FileSize>0 Then ''如果 FileSize > 0 说明有文件数据
Upload.SaveToFile Server.Mappath(SaveFile),FormName ''保存文件
'Upload.FileData(FormName) ''获取单个文件内容数据
''输出信息:
Response.Write "原文件名:" & File.FileName
Response.Write "<BR>"
Response.Write "文件表单名:" & File.FormName
Response.Write "<BR>"
Response.Write "文件来源路径:" & File.FilePath
Response.Write "<BR>"
Response.Write "文件名:" & FileName
Response.Write "<BR>"
Response.Write "文件类型(File.FileType):" & File.FileType
Response.Write "<BR>"
Response.Write "文件后缀(File.FileExt):" & File.FileExt
Response.Write "<BR>"
Response.Write "图像宽(File.FileWidth):" & File.FileWidth
Response.Write "<BR>"
Response.Write "图像高(File.FileHeight):" & File.FileHeight
Response.Write "<BR>"
Response.Write "文件大小(File.FileSize):" & File.FileSize
Response.Write "<BR>"
Response.Write "保存路径:" & SaveFile
Response.Write "<BR>"
Response.Write "图片上传成功!<p>"
End If
Set File=Nothing
Next
Response.Write "共上传"& Upload.Count &"个文件 ;By "& Upload.Version &"<p>"
End If
UseTime = Upload.UseTime '总消耗时间
CountSize = Upload.TotalBytes '上传总字节数
Response.Write "总执行时间:"& UseTime &"亳秒,平均速度:"& FormatNumber(CountSize/UseTime,2,-1,0,0) &" KB/s."
Set Upload=Nothing
End Sub

Function FormatPath(Path)
FormatPath = Replace(Path,Chr(0),"")
End Function

Function FormatName(FileExt)
Dim RanNum
Randomize
RanNum = Int(90000*rnd)+10000
FormatName = Year(now)&Month(now)&Day(now)&Hour(now)&Minute(now)&Second(now)&RanNum&"."&FileExt
End Function
%>

搜索更多相关主题的帖子: Upload Dim 代码 
2005-11-04 09:57
islet
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:89
帖 子:6548
专家分:0
注 册:2005-1-28
收藏
得分:0 
Upload.MaxSize = 50

这里改改看看
2005-11-04 10:38
lnsyhsz
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-11-4
收藏
得分:0 

我试过 不好用啊

2005-11-04 11:59
lnsyhsz
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-11-4
收藏
得分:0 

俺找到了 谢谢各位关注

2005-11-04 12:02
lnsyhsz
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-11-4
收藏
得分:0 
Upload.MaxSize = 50



Case 2 : Response.Write Upload.Description ''文件大小超过了限制 "&Upload.MaxSize/50&"K 


这样就可以了
2005-11-04 12:03
快速回复:[求助] 修改代码 大侠请进
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041052 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved