上传图片修改

2003-12-15 9:35:32 PM
  1. 上传图片的100K限制太小了,改成了200K
  2. 可上传图片增加了SWF格式

增加swf格式需要多做一个判断,如果后缀为swf,则不能使用[img]标记而用[swf],脚本预设swf宽500高350,不同的需要手工改动。
原本还想增加PNG格式,打开文件后发现原来已经支持的,只是上传页面没有注明。这两处早就想改的,后来不知怎么就忘记了,今天才想起来;)

此修改涉及文件为upfile.asp,其完整代码为:

<!--#include file="upload.inc"-->

<html>
<head>
<title>文件上传</title>
</head>
<body bgcolor=#EFEFEF>

<script>
parent.document.forms[0].Submit.disabled=false;
</script>
<%
dim upload,file,formName,formPath,iCount,filename,fileExt
set upload=new upload_5xSoft ''建立上传对象

formPath=upload.form("filepath")
''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"

response.write "<link rel='stylesheet' type='text/css' href='styles.css'>"
response.write "<body leftmargin=5 topmargin=3>"

iCount=0
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
if file.filesize<100 then
    response.write "<font size=2>请先选择你要上传的文件 [ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
    response.end
end if
    
if file.filesize>200*1000 then    'Poorfish修改为200K
    response.write "文件大小超过了限制200K [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
    response.end
end if

fileExt=lcase(right(file.filename,4))
uploadsuc=false
Forum_upload="gif,jpg,png,swf"    'Poorfish增加swf格式
Forumupload=split(Forum_upload,",")
for i=0 to ubound(Forumupload)
    if fileEXT="."&trim(Forumupload(i)) then
    uploadsuc=true
    exit for
    else
    uploadsuc=false
    end if
next
if uploadsuc=false then
    response.write "文件格式不正确 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
    response.end
end if

randomize
ranNum=int(90000*rnd)+10000
filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&fileExt

if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath(FileName) ''保存文件
    for i=0 to ubound(Forumupload)
        if fileEXT="."&trim(Forumupload(i)) then
            if fileEXT=".swf" then    'Poorfish加入上传文件格式判断
                response.write "<script>parent.NewLog.log_content.value+='[swf=500,350]"&FileName&"[/swf]'</script>"
            else
                 response.write "<script>parent.NewLog.log_content.value+='[img]"&FileName&"[/img]'</script>"
            end if
        exit for
        end if
    next
iCount=iCount+1
end if
set file=nothing
next
set upload=nothing ''删除此对象

Htmend iCount&" 个文件上传结束!"

sub HtmEnd(Msg)
set upload=nothing

response.write "上传成功 [ <a href=# onclick=history.go(-1)>继续上传</a> ]"
response.end
end sub


%>
</body>
</html>
[Edit on 2003-12-15 21:38:33 By poorfish]
Comments [4] | TrackBack[3] | 9137 views | TrackBack
s5s5 - 12/16/2003 5:25:23 PM
1
谢谢Poorfish,如果我想再加入RAR格式的上传功能,怎么加哩?
poorfish - 12/16/2003 5:39:20 PM
2
简单的做法就是给Forum_upload="gif,jpg,png,swf" 这一句加上rar了
readme - 11/2/2004 10:48:50 AM
3
我把文件上传大小设置为5M 5000*1000
之后,上传出错
提示, 服务器超时,应该如何解决呢谢谢。
ftbfguoybao - 7/10/2006 8:25:34 PM
4
在那里上传swf啊

Add your own comment

Name:       *

Password:

Code:        

Your Comment: