Fckeditor 2.6.3 (ASP版) ——添加上传文件大小限制
Fckeditor的修改还是在8月份进行的,本人比较懒,拖到现在才写出来,嘿嘿。
Fckeditor确实是一款强大的在线编辑器,设计比较人性化,兼容多个浏览器,如IE、firefox(我就测试了这两种哦)。对于FckEditor的修改,我主要进行了添加功能按钮、限制上传大小和过滤ASP木马三个方面的修改。今天先谈下对上传大小的限制的修改吧。
对于上传大小的修改,主要是三个方面:
(1)定义其允许上传的最大值。
这个是在fckeditor\editor\filemanager\connectors\asp\config.asp中修改的。在文件的最后添加如下代码:
Dim LinkUploadLimit,ImageUploadLimit,FlashUploadLimit,AttachUploadLimit,MediaUploadLimit
Dim LinkUploadMaxsize,ImageUploadMaxsize,FlashUploadMaxsize,AttachUploadMaxsize,MediaUploadMaxsize
'链接文件大小限制
LinkUploadLimit = True
LinkUploadMaxsize = 102400
'图片上传大小限制
ImageUploadLimit = True
ImageUploadMaxsize = 2048
'flash上传大小限制
FlashUploadLimit = True
FlashUploadMaxsize = 2048
'多媒体文件上传大小限制
MediaUploadLimit = True
MediaUploadMaxsize = 204800
'附件上传大小限制
AttachUploadLimit = True
AttachUploadMaxsize = 20480
Dim LinkUploadMaxsize,ImageUploadMaxsize,FlashUploadMaxsize,AttachUploadMaxsize,MediaUploadMaxsize
'链接文件大小限制
LinkUploadLimit = True
LinkUploadMaxsize = 102400
'图片上传大小限制
ImageUploadLimit = True
ImageUploadMaxsize = 2048
'flash上传大小限制
FlashUploadLimit = True
FlashUploadMaxsize = 2048
'多媒体文件上传大小限制
MediaUploadLimit = True
MediaUploadMaxsize = 204800
'附件上传大小限制
AttachUploadLimit = True
AttachUploadMaxsize = 20480
FckEditor针对不同的上传方式将上传文件分为link,Image,Flash,Media等类型(Attach类型为我添加的),分别对应Fckeditor工具栏上各个按钮的上传,如link对应使用超链接按钮创建超链接时上传的文件。因此这里对每种类型定义了两个变量一个用来设定是否开启上传限制,一个是上传的最大值,单位为k。
(2)判断上传的文件是否超过限制。
这个是在fckeditor\editor\filemanager\connectors\asp\commands.asp中修改的。
在172行之后即语句sOriginalFileName = sFileName之后添加如下代码
'此处添加对文件大小上传限制
Dim dFileSize,UploadLimitMaxsize,IsUploadLimit,IsLimitOk
'单位保持与设定值一致,设定值使用K
dFileSize=oUploader.File( "NewFile" ).Size/1024
'根据上传的类别,取设定值,是否允许上传,允许上传的最大值
select case sResourceType
case "File"
IsUpLoadLimit=LinkUploadLimit
UploadLimitMaxsize=LinkUploadMaxsize
case "Image"
IsUpLoadLimit=ImageUploadLimit
UploadLimitMaxsize=ImageUploadMaxsize
case "Flash"
IsUpLoadLimit=FlashUploadLimit
UploadLimitMaxsize=FlashUploadMaxsize
case "Media"
IsUpLoadLimit=MediaUploadLimit
UploadLimitMaxsize=MediaUploadMaxsize
case "Attach"
IsUpLoadLimit=AttachUploadLimit
UploadLimitMaxsize=AttachUploadMaxsize
'case "Media"
case else
'默认设定限制上传,最大为1M
IsUploadLimit=True
UploadLimitMaxsize=102400
end select
Dim dFileSize,UploadLimitMaxsize,IsUploadLimit,IsLimitOk
'单位保持与设定值一致,设定值使用K
dFileSize=oUploader.File( "NewFile" ).Size/1024
'根据上传的类别,取设定值,是否允许上传,允许上传的最大值
select case sResourceType
case "File"
IsUpLoadLimit=LinkUploadLimit
UploadLimitMaxsize=LinkUploadMaxsize
case "Image"
IsUpLoadLimit=ImageUploadLimit
UploadLimitMaxsize=ImageUploadMaxsize
case "Flash"
IsUpLoadLimit=FlashUploadLimit
UploadLimitMaxsize=FlashUploadMaxsize
case "Media"
IsUpLoadLimit=MediaUploadLimit
UploadLimitMaxsize=MediaUploadMaxsize
case "Attach"
IsUpLoadLimit=AttachUploadLimit
UploadLimitMaxsize=AttachUploadMaxsize
'case "Media"
case else
'默认设定限制上传,最大为1M
IsUploadLimit=True
UploadLimitMaxsize=102400
end select
'-------------读取上传设定结束-----------------------
'判断上传文件是否超过设定值,通过IsLimitOk来判定IsLimitOk=true 则无法上传
IsLimitOk=False
if IsUploadLimit then
if dFileSize > UploadLimitMaxsize then
IsLimitOk = True
sErrorNumber = "204"
end if
end if
'判断上传文件是否超过设定值,通过IsLimitOk来判定IsLimitOk=true 则无法上传
IsLimitOk=False
if IsUploadLimit then
if dFileSize > UploadLimitMaxsize then
IsLimitOk = True
sErrorNumber = "204"
end if
end if
'--------------判断结束,如果上传文件超过设定值,则设定错误代码为204-----
修改172行后的 DO While ……loop语句
Do While ( True )改为 Do While ( not IsLimitOk )
(3)定义客户端的错误提示信息。
客户端错误提示信息在每一类上传(如 link、image)对应的文件夹中的js文件中修改。
link:在fckeditor\editor\dialog\fck_link\下的fck_link.js中修改
修改函数function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg )中的switch …case 语句
即下列语句之后
case 203 :
alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ;
return ;
alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ;
return ;
添加如下代码:
case 204 :
alert( '文件大小超过设定值,不允许上传!' ) ;
return ;
alert( '文件大小超过设定值,不允许上传!' ) ;
return ;
其他类型按照相同方式修改即可。
出处:http://blog.csdn.net/togis/archive/2008/11/28/3405470.aspx
- 没有相关文章
- 没有评论