By default, FCKeditor does not change the name of the file to be uploaded. Therefore, for servers that do not support Chinese names, files with Chinese names uploaded locally cannot be accessed.
It is still saved to the server using the date and time naming method.
The whole process is to modify the source code of fck. net, compile and generate the directory where fredck. fckeditorv2.dll is stored in Bin.
Three changes are made:
Uploader. CS (fast upload, file rename)
Filebrowserconnector. CS (Upload by directory, rename the file)
Fileworkerbase. CS (stores files by year/year directory)
①
Use vs. Net to open fredck. fckeditorv2.csproj, open the uploader. CS file, and find 47 lines.
Int icounter = 0;
While (true)
{
String sfilepath = system. Io. Path. Combine (this. userfilesdirectory, sfilename );
If (system. Io. file. exists (sfilepath ))
{
Icounter ++;
Sfilename =
System. Io. Path. getfilenamewithoutextension (ofile. filename) +
"(" + Icounter + ")" +
System. Io. Path. getextension (ofile. filename );
Ierrornumber = 201;
}
Else
{
Ofile. saveas (sfilepath );
Sfileurl = This. userfilespath + sfilename;
Break;
}
}
This part of the Code indicates that the Upload File name is named according to the original file name. If there is a same name, add (n) to identify it.
Modify it
While (true)
{
// Rename the file
Sfilename = "hztt _" + datetime. Now. tostring ("yyyy-mm-dd
Hh: mm: SS fff "). Replace (" "," _ "). Replace (": ","-") +
System. Io. Path. getextension (ofile. filename );
String sfilepath = system. Io. Path. Combine (this. userfilesdirectory, sfilename );
Ofile. saveas (sfilepath );
// Output by year/month/directory
Sfileurl = This. userfilespath + datetime. Now. tostring ("yyyy-mm") + "/" + sfilename;
Break;
}
Datetime. Now. tostring ("yyyy-mm-dd
Hh: mm: SS ") is a string that obtains the current time and converts it to a formatted string. The result is 16:05:09.
123 format. The uploaded files are stored on the server as a Hztt_2007-07-01_16-05-09_123.gif.
②
Open the filebrowserconnector. CS file, find the fileupload function section in the Command handlers area, and modify row 215.
Int icounter = 0;
While (true)
{
String sfilepath = system. Io. Path. Combine (sserverdir, sfilename );
If (system. Io. file. exists (sfilepath ))
{
Icounter ++;
Sfilename =
System. Io. Path. getfilenamewithoutextension (ofile. filename) +
"(" + Icounter + ")" +
System. Io. Path. getextension (ofile. filename );
Serrornumber = "201 ";
}
Else
{
Ofile. saveas (sfilepath );
Break;
}
}
Modify:
While (true)
{
// Rename the file
Sfilename = "hztt _" +
Datetime. Now. tostring ("yyyy-mm-dd hh: mm: SS fff"). Replace ("",
"_"). Replace (":", "-") + system. Io. Path. getextension (ofile. filename );
String sfilepath = system. Io. Path. Combine (sserverdir, sfilename );
Ofile. saveas (sfilepath );
Break;
}
The uploaded files are also stored in the corresponding custom directory on the server (custom directory such as file image flash) in the name of Hztt_2007-07-01_16-05-09_123. GIF ).
③
Store files by month/year directory
Open the filebrowserconnector. CS file and modify lines 74.
Protected string userfilesdirectory
{
Get
{
If (suserfilesdirectory = NULL)
{
// Get the local (server) directory path translation.
Suserfilesdirectory = server. mappath (this. userfilespath );
}
Return suserfilesdirectory;
}
}
The function is used to save the image path and modify it:
Protected string userfilesdirectory
{
Get
{
If (suserfilesdirectory = NULL)
{
String userpath = server. mappath (this. userfilespath + datetime. Now. tostring ("yyyy-mm "));
If (! System. Io. Directory. exists (userpath) // create a folder
{
System. Io. Directory. createdirectory (userpath );
}
// Get the local (server) directory path translation.
Suserfilesdirectory = userpath;
}
If (! Suserfilesdirectory. endswith ("/"))
Suserfilesdirectory + = "/";
Return suserfilesdirectory;
}
}
Save the modified three Cs files, regenerate the solution, and overwrite the original fredck. fckeditorv2.dll in the \ bin \ DEBUG directory.
Click here to download related files
Upload/1/2007-42618-1-13.rar
The compressed package includes:
The bin directory contains the generated fredck. fckeditorv2.dll file.
The FCKeditor. net_2.2 source code of fck is in the backup directory,
The rest are the modified source code, which can be directly modified on this basis.