1. original configuration
Delete the FCKeditor/filemanager/connectors directory;
Some may ask how to upload files after they are all deleted?
Haha...
2. Do not reference fredck. fckeditorv2.dll;
Because I write them in JS instead of controls;
In fact, many people are attempting to inject data to the FCKeditor/filemanager/connectors directory,
Some people accidentally upload the fck editor to the Internet without any configuration;
3. Now let's get started. Generally, we don't need to use fck many times. There may be a few points in a system.
Now let's assume that I have a simple system with "news" and similar fck used in two places on the "Company Profile" single page.
I wantArticlePut the image in/article/yyyymmdd/guid.jpg
Put all single-page images on/page/yyyymmdd/guid.jpg
Or I want to save images to different places by users...
4. Implementation
It is too troublesome to make it clear that you need to make so many preparations ....!!!
Web page:
Code Copy codeThe Code is as follows: <Form ID = "form1" runat = "server">
<Div>
<Div>
<Asp: textbox id = "textbox1" textmode = "multiline" runat = "server"> </ASP: textbox>
</Div>
<Br/>
<Asp: button id = "button1" runat = "server" text = "button" onclick = "button#click"/>
</Div>
</Form>
JS:
CodeCopy codeThe Code is as follows: <SCRIPT src = "FCKeditor/FCKeditor. js" type = "text/JavaScript"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
Window. onload = function (){
VaR ofckeditor = new FCKeditor ('<% = textbox1.clientid %> ');
Ofckeditor. basepath = 'fckeditor /'
Ofckeditor. config. imageuploadurl = "/admin/auploader. aspx ";
Ofckeditor. replacetextarea ();
}
</SCRIPT>
This is done!
Don't believe it. Let's simply write the code for uploading the page, which is also important;
CodeCopy codeThe Code is as follows: protected void page_load (Object sender, eventargs E)
{
If (request. Files. Count> 0)
{
Httppostedfile file = request. Files [0];
String Path = "/article/" + system. datetime. Now. tostring ("yyyymmdd") + "/";
String serverpath = server. mappath (PATH );
String filename = guid. newguid () + file. filename. substring (file. filename. lastindexof ("."));
If (! System. Io. Directory. exists (serverpath ))
System. Io. Directory. createdirectory (serverpath );
File. saveas (serverpath + filename );
Sendfileuploadresponse (0, path + filename, filename, "Upload successful! ");
}
Else
{
Sendfileuploadresponse (1, "", "", "Upload Failed! ");
}
}
Public void sendfileuploadresponse (INT issucceed, string fileurl, string filename, string custommsg)
{< br> system. web. httpcontext. current. response. clear ();
system. web. httpcontext. current. response. write ("");
system. web. httpcontext. current. response. end ();
}
All right!
This upload code does not have strict suffix restrictions and size restrictions; because the page path is configured by ourselves, how can we write it;
You can even store data in different places based on different users;
Here we need to describe the sendfileuploadresponse method, which is actually sending a message for fck;
Here:
System. web. httpcontext. current. response. write ("window. parent. onuploadcompleted ("+ issucceed. tostring (). tolower () + ", '" + fileurl + "', '" + filename + "', '" + custommsg + "');");
Corresponding
FCKeditor/dialog/fck_image/fck_image.js
Code Copy code The Code is as follows: function onuploadcompleted (errornumber, fileurl, filename, custommsg)
{
// Remove Animation
Window. Parent. throbber. Hide ();
Gete ('didupload'). style. Display = '';
Switch (errornumber)
{
Case 0: // No errors
Alert ('Your file has been successfully uploaded ');
Break;
Case 1: // custom error
Alert (custommsg );
Return;
Case 101: // custom warning
Alert (custommsg );
Break;
Case 201:
Alert ('a file with the same name is already available. the uploaded file has been renamed to "'+ filename + '"');
Break;
Case 202:
Alert ('invalid file type ');
Return;
Case 203:
Alert ("security error. You probably don't have enough permissions to upload. Please check your server .");
Return;
Case 500:
Alert ('the connector is disabled ');
Break;
Default:
Alert ('error on File Upload. error number: '+ errornumber );
Return;
}
Sactualbrowser = '';
Seturl (fileurl );
Gete ('frmupload'). Reset ();
}
Note that 0 is a success, 1 is a failure, and others can see for themselves ....
By the way, we use version 2.65 for testing. If other versions have different flexibility;
Summary:
1. Configure different image processing paths on different pages, such:
Ofckeditor. config. imageuploadurl = "/admin/aupload. aspx ";
Ofckeditor. config. imageuploadurl = "/admin/bupload. aspx ";
....
2. fck will post the image to the specified path,
Then you can operate the image by yourself, save by directory, or save by current user session;
Of course, do not forget to verify the user's identity first. If you do not have the permission, do not be polite to the user and directly return an error,
I did not write the sample code for identity verification. Add the code according to the project.
3. Be sure to return the value to inform fck of your operation result, otherwise it will always die there...
PS:
It seems that I am not a fan of writing things...