FCKeditor Custom upload directory and automatically generate file name method

Source: Internet
Author: User
Tags current time datetime tostring

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.