在網站開發中,如果有發布類似新聞的圖文混排需求時,CKEditor不失為一個很好的選擇,下載地址如下:
它的前身是FCKEditor,隨着它的更新,上傳圖片的功能被分離出去了,現在如果需要實現上傳圖片,要么自己寫代碼,還有一種方法是使用CKFinder,下載地址如下:
下面詳細描述一下使用它們的時候如何配置。
CKEditor我下載的是3.6.4,CKFinder下載的是2.3 for ASP.NET,首先解壓所有的文件,然后將ckeditor和ckfinder文件夾放到網站的目錄下,可以刪除ckeditor和ckfinder文件夾下的_samples、_source 文件夾,將CKFinder.dll添加到站點的bin/文件夾中,然后在網站頁面頭部添加js的引用,具體路徑根據自己放置的路徑設置,如下:
<script src="../editor/ckeditor/ckeditor.js" type="text/javascript"></script> <script src="../editor/ckfinder/ckfinder.js" type="text/javascript"></script>
在頁面中添加一個textarea,具體代碼如下:
<textarea name="individual" id="individual" runat="server"></textarea> <script type="text/javascript"> CKEDITOR.replace('individual'); </script>
接下來打開ckeditor文件夾下的config.js文件,在CKEDITOR.editorConfig = function (config) {};方法中添加如下代碼:
config.filebrowserImageBrowseUrl = '../editor/ckfinder/ckfinder.html?Type=Images'; config.filebrowserFlashBrowseUrl = '../editor/ckfinder/ckfinder.html?Type=Flash'; config.filebrowserUploadUrl = '../editor/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files'; config.filebrowserImageUploadUrl = '../editor/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images'; config.filebrowserFlashUploadUrl = '../editor/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Flash'; config.filebrowserWindowWidth = '800'; //“瀏覽服務器”彈出框的size設置 config.filebrowserWindowHeight = '500';
上面的路徑也需要根據自己的設置。
然后打開ckfinder文件夾下面的config.ascx文件,為了所有的人都能看到服務器上上傳文件夾里面的文件,將函數public override bool CheckAuthentication返回值改為true,其實也可以根據自身網站的安全需要去更改代碼,這里只是為了簡單實現,代碼如下:
public override bool CheckAuthentication() { // WARNING : DO NOT simply return "true". By doing so, you are allowing // "anyone" to upload and list the files in your server. You must implement // some kind of session validation here. Even something very simple as... // // return ( Session[ "IsAuthorized" ] != null && (bool)Session[ "IsAuthorized" ] == true ); // // ... where Session[ "IsAuthorized" ] is set to "true" as soon as the // user logs on your system. return true; }
並且在public override void SetConfig()方法中找到BaseUrl,這個即為存放上傳文件的路徑,根據自己的網站進行更改。
整個配置過程就是上面部分,現在可以進行測試了。