设为首页收藏本站

新微赢技术网

 找回密码
 注册
搜索
热搜: 回贴
查看: 41|回复: 1
打印 上一主题 下一主题

[求助] 修改代码 大侠请进

[复制链接]
跳转到指定楼层
1#
发表于 2010-1-13 07:37:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这个是 一个上传的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
%>
您需要登录后才可以回帖 登录 | 注册

本版积分规则

申请友链|小黑屋|最新主题|手机版|新微赢技术网 ( 苏ICP备08020429号 )  

GMT+8, 2024-11-20 09:25 , Processed in 0.099821 second(s), 9 queries , Gzip On, Memcache On.

Powered by xuexi

© 2001-2013 HaiAn.Com.Cn Inc. 寰耽

快速回复 返回顶部 返回列表