關于UEditor編輯器遠程圖片上傳失敗的解決辦法
Jun 13, 2016 am 11:58 AM
遠程圖片上傳是個很有意思的東西,比如你從別的網(wǎng)站復制一段文件,如果文字中帶有圖片,編輯器會自動將圖片提取出來,進行上傳,從而不用擔心遠程圖片失效后,自己本地也無法瀏覽。
通過檢查,發(fā)現(xiàn)遠程圖片上傳的操作頁面是:getRemoteImage.php 。打開后我們先配置 savePath ,因為不同用戶使用,需要存放到不同的目錄,以免混亂,也方便管理
修改后代碼:
復制代碼 代碼如下:
//遠程抓取圖片配置
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 , //保存路徑
"allowFiles" => array( ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" ) , //文件允許格式
"maxSize" => 3000 //文件大小限制,單位KB
);
然后問題就來了,UEditor 里,文件、圖片上傳都是通過 Uploader.class.php 這個php類操作的,但遠程圖片上傳則不是。
我在85行發(fā)現(xiàn),創(chuàng)建路徑的時候,單純的使用了mkdir進行來創(chuàng)建,因為mkdir不能創(chuàng)建帶有層級的路徑,所以導致在路徑如果不存在的情況下,復制遠程圖片上傳失敗。
知道問題處理起來就容易了,我先寫一個循環(huán)創(chuàng)建文件目錄的函數(shù)(因為之前寫過,這里就直接拿來用了):
復制代碼 代碼如下:
//連續(xù)創(chuàng)建帶層級的文件夾
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;
}
}
然后修改85行:
復制代碼 代碼如下:
//創(chuàng)建保存位置
$savePath = $config[ 'savePath' ];
if ( !file_exists( $savePath ) ) {
recursive_mkdir($savePath);
//mkdir( "$savePath" , 0777 );
}
這樣一來,就沒有問題了。
這問題也已經(jīng)提交給百度官方,希望修正。
測試UEditor版本為1.2.3.0,如果之前版本也有相關問題,按照修改思路去修改應該也可以解決。

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

As smartphone technology continues to develop, mobile phones play an increasingly important role in our daily lives. As a flagship phone focusing on gaming performance, the Black Shark phone is highly favored by players. However, sometimes we also face the situation that the Black Shark phone cannot be turned on. At this time, we need to take some measures to solve this problem. Next, let us share five tips to teach you how to solve the problem of Black Shark phone not turning on: Step 1: Check the battery power. First, make sure your Black Shark phone has enough power. It may be because the phone battery is exhausted

With the continuous development of social media, Xiaohongshu has become a platform for more and more young people to share their lives and discover beautiful things. Many users are troubled by auto-save issues when posting images. So, how to solve this problem? 1. How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? 1. Clear the cache First, we can try to clear the cache data of Xiaohongshu. The steps are as follows: (1) Open Xiaohongshu and click the "My" button in the lower right corner; (2) On the personal center page, find "Settings" and click it; (3) Scroll down and find the "Clear Cache" option. Click OK. After clearing the cache, re-enter Xiaohongshu and try to post pictures to see if the automatic saving problem is solved. 2. Update the Xiaohongshu version to ensure that your Xiaohongshu

With the popularity of Douyin short videos, user interactions in the comment area have become more colorful. Some users wish to share images in comments to better express their opinions or emotions. So, how to post pictures in TikTok comments? This article will answer this question in detail and provide you with some related tips and precautions. 1. How to post pictures in Douyin comments? 1. Open Douyin: First, you need to open Douyin APP and log in to your account. 2. Find the comment area: When browsing or posting a short video, find the place where you want to comment and click the "Comment" button. 3. Enter your comment content: Enter your comment content in the comment area. 4. Choose to send a picture: In the interface for entering comment content, you will see a "picture" button or a "+" button, click

Everyone knows that if the computer cannot load the driver, the device may not work properly or interact with the computer correctly. So how do we solve the problem when a prompt box pops up on the computer that the driver cannot be loaded on this device? The editor below will teach you two ways to easily solve the problem. Unable to load the driver on this device Solution 1. Search for "Kernel Isolation" in the Start menu. 2. Turn off Memory Integrity, and it will prompt "Memory Integrity has been turned off. Your device may be vulnerable." Click behind to ignore it, and it will not affect the use. 3. The problem can be solved after restarting the machine.

In PowerPoint, it is a common technique to display pictures one by one, which can be achieved by setting animation effects. This guide details the steps to implement this technique, including basic setup, image insertion, adding animation, and adjusting animation order and timing. Additionally, advanced settings and adjustments are provided, such as using triggers, adjusting animation speed and order, and previewing animation effects. By following these steps and tips, users can easily set up pictures to appear one after another in PowerPoint, thereby enhancing the visual impact of the presentation and grabbing the attention of the audience.

Some netizens found that when they opened the browser web page, the pictures on the web page could not be loaded for a long time. What happened? I checked that the network is normal, so where is the problem? The editor below will introduce to you six solutions to the problem that web page images cannot be loaded. Web page images cannot be loaded: 1. Internet speed problem The web page cannot display images. It may be because the computer's Internet speed is relatively slow and there are more softwares opened on the computer. And the images we access are relatively large, which may be due to loading timeout. As a result, the picture cannot be displayed. You can turn off the software that consumes more network speed. You can go to the task manager to check. 2. Too many visitors. If the webpage cannot display pictures, it may be because the webpages we visited were visited at the same time.

When using WPS office software, we found that not only one form is used, tables and pictures can be added to the text, pictures can also be added to the table, etc. These are all used together to make the content of the entire document look richer. , if you need to insert two pictures into the document and they need to be arranged side by side. Our next course can solve this problem: how to place two pictures side by side in a wps document. 1. First, you need to open the WPS software and find the picture you want to adjust. Left-click the picture and a menu bar will pop up, select "Page Layout". 2. Select "Tight wrapping" in text wrapping. 3. After all the pictures you need are confirmed to be set to "Tight text wrapping", you can drag the pictures to the appropriate position and click on the first picture.

Black Shark is a smartphone brand known for its powerful performance and excellent gaming experience. It is loved by gamers and technology enthusiasts. However, just like other smartphones, Black Shark phones will have various problems, among which charging failure is a common one. Charging failure will not only affect the normal use of the mobile phone, but may also cause more serious problems, so it is very important to solve the charging problem in time. This article will start with the common causes of Black Shark mobile phone charging failures and introduce methods to troubleshoot and solve charging problems. I hope it can help readers solve the problem of Black Shark mobile phones.
