DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> WEB網站前端 >> WEB前端代碼
讓 CKEditor/CKFinder 依日期建立上傳資料夾
編輯:WEB前端代碼     

有時我們希望 CKEditor 搭配的 CKFinder 在上傳檔案時,能依日期自動建立對應的資料夾,方便分類管理。做法是修改 /ckfinder/config.ascx 檔。

關鍵是先產生一段日期格式的字串,再把它拼接進各資源類型的路徑中:

string dateDir = DateTime.Today.ToString("yyyyMM/");

ResourceType type;
type = ResourceType.Add( "Files" );
type.Url = BaseUrl + "files/" + dateDir;
type.Dir = BaseDir == "" ? "" : BaseDir + "files/" + dateDir;
type.MaxSize = 0;
type.AllowedExtensions = new string[] { "7z", "aiff", "asf", "avi", "bmp", "csv", "doc", "docx", "fla", "flv", "gif", "gz", "gzip", "jpeg", "jpg", "mid", "mov", "mp3", "mp4", "mpc", "mpeg", "mpg", "ods", "odt", "pdf", "png", "ppt", "pptx", "pxd", "qt", "ram", "rar", "rm", "rmi", "rmvb", "rtf", "sdc", "sitd", "swf", "sxc", "sxw", "tar", "tgz", "tif", "tiff", "txt", "vsd", "wav", "wma", "wmv", "xls", "xlsx", "zip" };
type.DeniedExtensions = new string[] { };

type = ResourceType.Add( "Images" );
type.Url = BaseUrl + "images/" + dateDir;
type.Dir = BaseDir == "" ? "" : BaseDir + "images/" + dateDir;
type.MaxSize = 0;
type.AllowedExtensions = new string[] { "bmp", "gif", "jpeg", "jpg", "png" };
type.DeniedExtensions = new string[] { };

type = ResourceType.Add( "Flash" );
type.Url = BaseUrl + "flash/" + dateDir;
type.Dir = BaseDir == "" ? "" : BaseDir + "flash/" + dateDir;
type.MaxSize = 0;
type.AllowedExtensions = new string[] { "swf", "flv" };
type.DeniedExtensions = new string[] { };

這段程式的重點在於 dateDir 變數:透過 DateTime.Today.ToString("yyyyMM/") 產生形如「202609/」的目錄名稱,再把它附加到 Files、Images、Flash 三種資源的 Url 與 Dir 上。如此一來,每個月份的上傳檔案就會自動歸入以年月命名的資料夾中,讓檔案結構更清楚、更容易維護。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved