Baidu ueditor editor remote picture upload failed

Source: Internet
Author: User
Tags mkdir php class

Remote image upload is a very interesting thing, such as you copy a file from another site, if the text with a picture, the editor will automatically extract the picture, upload, so do not worry about the remote image after the failure of their own local can not browse.

Through the check, found that the remote Picture Upload action page is: getremoteimage.php. After opening, we first configure the Savepath, because different users need to be stored in a different directory, so as to avoid confusion, but also easy to manage

Modified code:

The code is as follows Copy Code
?//remote capture picture configuration
if (isset ($_session[' admin ')) {
    $myPath = ' http:///... /dofiles/ueditorupload/admin/'. $_session[' admin ' [' id ']. ' /';
}else if (isset $_session[' user ')) {
    $myPath = ' http:///... /dofiles/ueditorupload/user/'. $_session[' user ' [' id ']. ' /';
}else{
    $myPath = ' http:///. /dofiles/ueditorupload/unkonw/';
}
$config = Array (
    "Savepath" => $myPath,            //save path
    "Allowfiles" => Array (". gif", ". png", ". jpg", ". jpeg", ". MP "),//file Allow format
   " MaxSize "=> 3000                    //File size limit, per KB
);

Then the problem comes, ueditor, file, picture upload is through Uploader.class.php this PHP class operation, but the remote picture upload is not.

I found in line 85, creating the path, simply using the mkdir to create, because the mkdir can not create a hierarchical path, so that if the path does not exist, replication of remote picture upload failed.

Knowing the problem is easy, I'm going to write a loop to create the file directory (because I've written it before and it's used here directly):

?//Create a folder with levels continuously

The code is as follows Copy Code
function Recursive_mkdir ($folder) {
$folder = Preg_split ("/[\\/]/", $folder);
$mkfolder = ';
For ($i =0 isset ($folder [$i]); $i + +) {
if (!strlen ($folder [$i])) {
Continue
}
$mkfolder. = $folder [$i];
if (!is_dir ($mkfolder)) {
mkdir ("$mkfolder", 0777);
}
$mkfolder. = Directory_separator;
}
}

Then modify the 85 lines:

?//Create Save location

The code is as follows Copy Code
$savePath = $config [' Savepath '];
if (!file_exists ($savePath)) {
Recursive_mkdir ($savePath);
mkdir ("$savePath", 0777);
}

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.