FCKeditor Custom upload directory and automatically generate file name method
Using the FCKeditor upload function, we will find that the uploaded file name and local is the same, will not automatically change the filename, so sometimes local is the Chinese file name is not too good. The following is my fckeditor.net source file modification, so that the upload file automatically generated random file name, and upload directory according to the current time classification, so easy to manage!
The fckeditor.net 2.6.3 version is used below.
1, according to the current time set upload directory
Open the FileBrowserConfig.cs file and add the following code on line 119 (Userfilespath + = +;):
1
2
3//According to the current time settings upload directory
Chenghai Tao 2008-12-31 Revision
Userfilespath + + = DateTime.Now.Year.ToString () + "/" + DateTime.Now.Month.ToString () + "/";
2, automatically generate a new file name
Open the FileBrowserFileWorkerBase.cs file and add the code below 56 lines:
1
2
3
4
5
6///Create new file name based on current time
Chenghai Tao 2008-12-31 Revision
Random Rnd = new Random ();
int strrnd = Rnd.next (1, 99);
sFileName = DateTime.Now.Day.ToString () + DateTime.Now.Hour.ToString () + DateTime.Now.Minute.ToString () + DateTime.Now.Second.ToString () + strrnd.tostring ();
sFileName + = "." + Sextension.tolower ();
Now that the project is republished, you can find that the file is uploaded to the specified directory and the file name is randomly generated.