Solution to remote image Upload failure in UEditor

Source: Internet
Author: User
Because I like the UEditor interface, I replaced the original editor in the project, but I found some problems in subsequent operations, remote Image Upload remote image upload is an interesting thing. 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:

Copy codeThe 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 ):

Copy codeThe 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:
Copy codeThe 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.

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.