Because I like the UEditor interface, I replaced the original editor in the project. However, some problems were found in subsequent operations, that is, remote image upload to UEditor.
Remote Image upload is very interesting. for example, if you copy a file from another website and the text contains an image, the editor automatically extracts the image and uploads it, in this way, you do not need to worry that the remote image cannot be viewed locally after it becomes invalid.
After checking, it is found that the operation page for remote image upload is getRemoteImage. php. After opening, we configure savePath first. because different users need to store it in different directories to avoid confusion and facilitate management.
Code after modification:
The code is as follows:
// Configure remote image capturing
If (isset ($ _ SESSION ['admin']) {
$ MyPath = 'http: // response
} Else if (isset ($ _ SESSION ['user']) {
$ MyPath = 'http: // response
} Else {
$ MyPath = 'http: // www.bitscn.com/./dofiles/ueditorupload/unkonw /';
}
$ Config = array (
"SavePath" => $ myPath, // save path
"AllowFiles" => array (". gif", ". png", ". jpg", ". jpeg", ". bmp"), // file format allowed
"MaxSize" => 3000 // file size limit, in KB
);
Then the problem arises. in UEditor, files and images are uploaded through the php class Uploader. class. php, but remote image uploading is not.
I found in row 85 that when creating a path, mkdir is used to create it. because mkdir cannot create a path with a level, if the path does not exist, an error occurred while uploading the copied remote image.
It is easy to solve the problem. I will first write a function to create a file directory in a loop (because it was previously written, it will be used directly here ):
The code is as follows:
// Create a hierarchical folder consecutively
Function recursive_mkdir ($ folder ){
$ Folder = preg_split ("/[\\\\/]/", $ folder );
$ Mkfolder = '';
For ($ I = 0; isset ($ folder [$ I]); $ I ++ ){
If (! Strlen (trim ($ folder [$ I]) {
Continue;
}
$ Mkfolder. = $ folder [$ I];
If (! Is_dir ($ mkfolder )){
Mkdir ("$ mkfolder", 0777 );
}
$ Mkfolder. = DIRECTORY_SEPARATOR;
}
}
Then modify row 85:
The code is as follows:
// Create a storage location
$ SavePath = $ config ['savepath'];
If (! File_exists ($ savePath )){
Recursive_mkdir ($ savePath );
// Mkdir ("$ savePath", 0777 );
}
In this way, there is no problem.
This problem has also been submitted to Baidu official, hoping to be corrected.
The UEditor version is 1.2.3.0. if there are problems with the previous version, you can modify the version according to the modification idea.