如何在自己的網站中架設fckeditor編輯器我就不說了,本文預設你已經架設過並且熟悉fckeditor內部結構。
在下載fckeditor編輯器的同時,如果是使用.net版本,還必須下載一個原始碼包,在裡面有一些功能類,和編譯出來的dll檔案,存放在bin檔案中,我們所需要做的就是修改原始碼,獲得新的dll,在自己的網站中替換就可以了。
(原始碼版本號碼是fckeditor.net_2.5,編輯器檔案版本號碼為fckeditor_2.6.2)
實用vs2005開啟程式碼封裝根目錄下的fredck.fckeditorv2.vs2005.csproj檔案,待檔案樹展開後,找到filebrowser檔案夾下的fileworkerbase.cs檔案,對其進行修改。
我們需要的是修改fileworkerbase類中的fileupload方法函數。
在看代碼之前先簡單的介紹一下我的想法。我在自己的網站中建立了general.config檔案,用於存放網站的一些配置資訊,如浮水印的類型(文字型,圖片型),是否需要加浮水印,文字型浮水印的文字內容等等和本文無關的重要配置資訊。所以在如下帶代碼中,有一段是用來讀取這些配置資訊的。
在fileupload方法中找到ofile.saveas( sfilepath );語句
try
{
dataset configds = new dataset();
configds.readxml(server.mappath("~/config/general.config"));
datatable configdt = configds.tables[0];
if (configdt.rows[0]["watermarkstatus"].tostring() == "1")
{
image img = image.fromfile(sfilepath);
if (configdt.rows[0]["watermarktype"].tostring() == "0")
{
graphics g = graphics.fromimage(img);
g.drawimage(img, 0, 0, img.width, img.height);
font f = new font("華文行楷", 40);
brush b = new solidbrush(color.white);
string addtext = configdt.rows[0]["watermarktext"].tostring();
g.drawstring(addtext, f, b, img.width - 174, img.height - 40);
g.dispose();
}
if (configdt.rows[0]["watermarktype"].tostring() == "1")
{
system.drawing.image copyimage = system.drawing.image.fromfile(server.mappath("~/watermark/watermark.gif"));
graphics g = graphics.fromimage(img);
g.drawimage(copyimage, new rectangle(img.width - copyimage.width, img.height - copyimage.height, copyimage.width, copyimage.height), 0, 0, copyimage.width, copyimage.height, graphicsunit.pixel);
g.dispose();
}
sfilename = system.io.path.getfilenamewithoutextension(ofile.filename);
string newpath = sfilename+"_"+datetime.now.tostring("yymmddhhmmss") + "." + sextension;
newpath = system.io.path.combine(sserverdir, newpath);
sfilename = newpath;
img.save(newpath);
img.dispose();
if (file.exists(sfilepath))
{
file.delete(sfilepath);
}
}
}
catch
{
this.sendfileuploadresponse(808, isquickupload);
}