Solution to the failure of remote image upload in UEditor editor_PHP tutorial

WBOY
Release: 2016-07-21 15:16:23
Original
773 people have browsed it

Remote image upload is a very interesting thing. For example, if you copy a file from another website, if the text contains an image, the editor will automatically extract the image and upload it, so you don't have to worry about the remote image being invalid and not being able to access it locally. Browse.

Through inspection, it was found that the operation page for remote image upload is: getRemoteImage.php. After opening, we first configure savePath, because different users need to store it in different directories to avoid confusion and facilitate management

Modified code:

Copy the code The code is as follows:

//Remote image capture configuration
if(isset($_SESSION['admin'])){
$myPath = 'http://www.jb51.net/../dofiles/ueditorUpload/admin/'.$_SESSION['admin']['id'].'/';
}else if(isset($_SESSION ['user'])){
$myPath = 'http://www.jb51.net/../dofiles/ueditorUpload/user/'.$_SESSION['user']['id'].' /';
}else{
$myPath = 'http://www.jb51.net/../dofiles/ueditorUpload/unkonw/';
}
$config = array(
"savePath" => $myPath , //Save path
"allowFiles" => array( ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" ), //File allowed format
"maxSize" => 3000 //File size limit, unit KB
);


Then the problem comes, in UEditor , file and image upload are all operated through the Uploader.class.php PHP class, but remote image upload is not.

I found on line 85 that when creating the path, mkdir was simply used to create it. Because mkdir cannot create a hierarchical path, the remote image will be copied if the path does not exist. Upload failed.

Knowing that the problem is easier to deal with, I will first write a function that creates a file directory in a loop (because I have written it before, I will use it directly here):

Copy code The code is as follows:

//Continuously create hierarchical folders
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 85 Line:
Copy code The code is as follows:

//Create save location
$savePath = $config[ 'savePath ' ];
if ( !file_exists( $savePath ) ) {
recursive_mkdir($savePath);
//mkdir( "$savePath" , 0777 );
}

In this case, there will be no problem.

This problem has also been submitted to Baidu officials, hoping to correct it.

The tested UEditor version is 1.2.3.0. If there are related problems in the previous version, it should be able to be solved by modifying according to the modification ideas.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325896.htmlTechArticleRemote image upload is a very interesting thing. For example, if you copy a file from another website, if the text contains Picture, the editor will automatically extract the picture and upload it from...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!