我使用的是Fckeditor_net_2.6.3版本,配置后可正常使用,现在就是无法限制上传图片大小,网上资料是在Uploader.cs文件中加上如下代码:if(oFile.ContentLength>(200*1024)) //限制在200kb以下
{
SendResults(204);
return ;
}
但加上去以后,限制无效,不知道那位朋友遇到过这样的问题,怎么解决的?
{
SendResults(204);
return ;
}
但加上去以后,限制无效,不知道那位朋友遇到过这样的问题,怎么解决的?
using System;
using System.Globalization;
using System.Xml;
using System.Web; namespace FredCK.FCKeditorV2
{
public class Uploader : FileWorkerBase
{
protected override void OnLoad(EventArgs e)
{
// Get the posted file.
HttpPostedFile oFile = Request.Files[ "NewFile "]; // Check if the file has been correctly uploaded
if (oFile == null || oFile.ContentLength == 0)
{
SendResults(202);
return;
} int iErrorNumber = 0;
string sFileUrl = " "; // Get the uploaded file name.
string sFileName = System.IO.Path.GetFileName(oFile.FileName); int iCounter = 0; while (true)
{
//判断文件是否可以上传
if (CheckUploadFileExtension(sFileName))
{
string sFilePath = System.IO.Path.Combine(this.UserFilesDirectory, sFileName); if (System.IO.File.Exists(sFilePath))
{
iCounter++;
sFileName =
System.IO.Path.GetFileNameWithoutExtension(oFile.FileName) +
"( " + iCounter + ") " +
System.IO.Path.GetExtension(oFile.FileName); iErrorNumber = 201;
}
else
{
oFile.SaveAs(sFilePath);
sFileUrl = this.UserFilesPath + sFileName;
break;
}
}
else
{
//不允许上传
SendResults(202);
break;
}
} SendResults(iErrorNumber, sFileUrl, sFileName);
} #region SendResults Method private void SendResults(int errorNumber)
{
SendResults(errorNumber, " ", " ", " ");
} private void SendResults(int errorNumber, string fileUrl, string fileName)
{
SendResults(errorNumber, fileUrl, fileName, " ");
} private void SendResults(int errorNumber, string fileUrl, string fileName, string customMsg)
{
Response.Clear(); Response.Write( " <script type=\ "text/javascript\ "> ");
Response.Write( "window.parent.OnUploadCompleted( " + errorNumber + ", ' " + fileUrl.Replace( " ' ", "\\ ' ") + " ', ' " + fileName.Replace( " ' ", "\\ ' ") + " ', ' " + customMsg.Replace( " ' ", "\\ ' ") + " ') ; ");
Response.Write( " </script> "); Response.End();
} #endregion
}
}
Uploader.cs代码如下------------------------------------ /*
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
* Copyright (C) 2003-2007 Frederico Caldeira Knabben
*
* == BEGIN LICENSE ==
*
* Licensed under the terms of any of the following licenses at your
* choice:
*
* - GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
* http://www.gnu.org/licenses/lgpl.html
*
* - Mozilla Public License Version 1.1 or later (the "MPL")
* http://www.mozilla.org/MPL/MPL-1.1.html
*
* == END LICENSE ==
*
* This is the code behind of the uploader.aspx page used for Quick Uploads.
*/using System ;
using System.Globalization ;
using System.Xml ;
using System.Web ;namespace FredCK.FCKeditorV2.FileBrowser
{
public class Uploader : FileWorkerBase
{
protected override void OnLoad(EventArgs e)
{
this.Config.LoadConfig(); if ( !Config.Enabled )
{
this.SendFileUploadResponse( 1, true, "", "", "链接无效,请检查 \"editor/filemanager/connectors/aspx/config.aspx\" file." );
return;
}
//设置文件上传图片文件大小 if (sFile.ContentLength > 120*1024)
{
SendResults(204);
return;
}
string sResourceType = Request.QueryString[ "Type" ]; if ( sResourceType == null )
{
this.SendFileUploadResponse( 1, true, "", "", "请求无效." );
return;
} // Check if it is an allowed type.
if ( !Config.CheckIsTypeAllowed( sResourceType ) )
{
this.SendFileUploadResponse( 1, true, "", "", "Invalid resource type specified." );
return;
} this.FileUpload( sResourceType, "/", true );
}
}
}
当前上下问中不存在名称“SendResults”