[Records of various problems encountered during the project] editor-FCKeditor custom upload path Configuration

Source: Internet
Author: User

In the previous article, I introduced some knowledge about FCKeditor and Some Problems and Solutions I encountered during usage, today, this article mainly records how to use FCKeditor to classify and manage uploaded files.

The following is what we will introduce:

1. FCKeditor Upload File Analysis

2. FCKeditor file path classification configuration implementation

 

I. FCKeditor Upload File Analysis

All those who have used FCKeditor know that all files uploaded by FCKeditor are stored in a custom directory, and only four directories are saved according to the file type: file, Flash, image, and media (FCKeditor has a built-in manager that allows you to create folders freely. However, this is disabled because it is not secure. All you need to do is upload files.In the actual application process, it is impossible for us to put these files of the same type in a folder. We need special logic to store them, for example: news files are stored by month, and blog resources are stored by the user name of the blogger. At this time, FCKeditor basically cannot meet my needs, therefore, we need to study the source code of FCKeditor for simple modification to achieve our goal.

FCKeditor consists of two parts, one of which is the HTML package of FCKeditor. The JS and HTML pages are mainly responsible for interaction with the client, and the other part is the specific C #ProgramSet fredck. fckeditorv2.

The FCKeditor upload part consists of two parts:

1. For the client usercontrol -- config. ascx (stored in FCKeditor \ editor \ filemanager \ connectors \ aspx)

2. The server is responsible for uploading specific classes: fredck. fckeditorv2.filebrowser. config. CS

Let's take a look at the class relationship diagram in fredck. fckeditorv2:

In this class diagram, there are three main types of fileworkerbase, typeconfig, and config for uploading files. The following describes the three classes respectively:

1. fileworkerbase, an abstract class, is mainly responsible for file management. The file uploading is mainly fileupload (responsible for file going to bed) and servermapfolder (locating the path address on the server) these two methods (you can view the source code for specific content ).

2. typeconfig. This class is mainly used to assist fileworkerbase and provide the required path for fileworkerbase.

3. config: the specific background class of the user control, responsible for interacting with the front-end user control.

Originally, my idea was implemented through the FCKeditor class. In this way, you only need to set the corresponding attributes on the actual page control. Unfortunately, it is not feasible during the actual study, because the file management module of FCKeditor is separate from its control class and file upload needs to be implemented through fileworkerbase, the properties configured on the FCKeditor Control cannot be obtained in fileworkerbase, so we have to do it from the three classes mentioned above.Article.

 

Ii. FCKeditor File Upload path classification configuration implementation

Now we need to configure the path of the file to be uploaded. First, we can know that the fileworkerbase. fileupload method is used to upload files, where:

 
String sserverdir = This. servermapfolder (resourcetype, CurrentFolder, isquickupload );

This sentenceCodeIs used to obtain the saved path. Once we know this, we can find a way to change the value of the CurrentFolder variable to the path we configured.

In this case, the user control config needs to appear, because this user control is mainly exposed to the client, responsible for interacting with the client, we can check its code and find that its ascx contains a piece of server script code. The setconfig method is used to set the types allowed for uploading files and the default upload path, so we only need to add our configuration here.

First, add a new attribute in fredck. fckeditorv2.filebrowser. config. CS:

 
Public String uploadpath {Get; set ;}

This attribute is used to set the specific personalized path for storing uploaded files. It does not conflict with the configured FCKeditor: userfilespath, because FCKeditor: userfilespath is used to set the root path for storing all files, such as: "~ /Upload/", while uploadpath is a personalized path based on the upload root directory, such as" news, after adding this attribute, you can add a specific configuration path to the ascx file, for example:

 
Uploadpath = "News/" + datetime. Now. year. tostring () + datetime. Now. Month. tostring ();

I configured a news configuration, which is separated by year and month.

This step is not over yet. You still need to perform two steps:

1. close the file browser in fckconfig. fckconfig. linkbrowser, fckconfig. imagebrowser and fckconfig. flashbroload is set to false, so that you can only upload images through the upload tab (that is, quick upload-quickupload in FCKeditor code), and cannot view files on the server:

2. Change the path to get the code. In the typeconfig class, change the getquickuploadpath Method to the following code:

Internal string getquickuploadpath () {string Path = This. fileworker. config. uploadpath; If (_ quickuploadpath = NULL & string. isnullorempty (PATH) = false) _ quickuploadpath = quickuploadpath. replace ("% userfilespath %", system. io. path. combine (this. fileworker. config. userfilespath, PATH); Return _ quickuploadpath ;}

The path is changed to get the uploadpath from the user control config, and then the combined path is/upload/news/201012.

 

In this way, the FCKeditor file path classification configuration has been completed to achieve this goal. However, if you want to add a path, you need to add an HTML package of FCKeditor to the website, FCKeditor \ editor \ filemanager \ connectors \ aspx \ config. modify the uploadpath configuration in the ascx control. If you have other solutions, please share them!

 

Source code download: Click here to download (you can directly browse the default. aspx under the root directory of the website)

 

In other words, if you think this article is useful or valuable, move the cursor over [recommendation] and click it for me. Thank you very much!

 

Records of various problems encountered during the project process

Editor:

FCKeditor related knowledge and various common usage Problems

FCKeditor custom upload path Configuration

Chart:

Tips on mschart

Good chart selection on ASP.net-funsioncharts

Orm:

Some minor issues with using nhib.pdf to configure object entities

About Nhibernate query Encapsulation

Deployment:

Problems related to project deployment-IIS

The tangled problems during project deployment-sqlserver

Tools:

. Net tool library that is frequently used for Development (a tool for mutual transfer between C # and VB. NET)

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.