Table of Contents
ThinkPHP integrates Baidu Ueditor graphic tutorial,
Home Backend Development PHP Tutorial ThinkPHP integrates Baidu Ueditor graphic tutorial, _PHP tutorial

ThinkPHP integrates Baidu Ueditor graphic tutorial, _PHP tutorial

Jul 13, 2016 am 10:16 AM
thinkphp Integrate Baidu

ThinkPHP integrates Baidu Ueditor graphic tutorial,

ThinkPHP integrates Baidu Ueditor, based on teacher Huang Yongcheng’s video explanation
Disclaimer: It is best if everyone can write absolute paths, such as: window.UEDITOR_HOME_URL

He has already said it in the tutorial, so I won’t say it again, I will just mention it in one sentence, no nonsense!

When calling the editor, first initialize some values:

<script type="text/javascript" charset="utf-8">
  window.UEDITOR_HOME_URL = "/Public/ueditor/"; //UEDITOR_HOME_URL、config、all这三个顺序不能改变
  window.onload=function(){
    window.UEDITOR_CONFIG.initialFrameHeight=300;//编辑器的高度
    window.UEDITOR_CONFIG.imageUrl="{:U('admin/Category/checkPic')}";     //图片上传提交地址
    window.UEDITOR_CONFIG.imagePath=' /Uploads/thumb/';//编辑器调用图片的地址
    UE.getEditor('contents');//里面的contents是我的textarea的id值
    
    }
 
</script>
Copy after login

Then introduce 2 js files, namely: 1. ueditor.all.min.js 2. ueditor.config.js
I would like to state here that the order of the calling methods I mentioned above must not be messed up. If it is messed up, problems will occur, so you should follow my step-by-step method!

Because I rewrote the editor’s image submission address, I also had to write a method for image processing in the controller.

The code is as follows:

//改变Ueditor 默认图片上传路径
    public function checkPic(){
      import('ORG.Net.UploadFile');
       $upload = new UploadFile();// 实例化上传类
       $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
       $upload->autoSub =true ;
       $upload->subType ='date' ;
       $upload->dateFormat ='ym' ;
       $upload->savePath = './Uploads/thumb/';// 设置附件上传目录
       if($upload->upload()){
         $info = $upload->getUploadFileInfo();
         echo json_encode(array(
          'url'=>$info[0]['savename'],
          'title'=>htmlspecialchars($_POST['pictitle'], ENT_QUOTES),
          'original'=>$info[0]['name'],
          'state'=>'SUCCESS'
         ));
       }else{
         echo json_encode(array(
         'state'=>$upload->getErrorMsg()
         ));
           }
 
      }
Copy after login

I will show you the code first, and then continue to explain,

1. Introduce tp’s official file upload processing class, and then initialize some configurations. These are not introduced!

2. Determine whether the upload is successful. If the upload is successful, first obtain the information of successful upload, then convert the array into json and use phpjson_encode. If the upload fails, the upload failure information will be returned directly!

The above are all explained in Teacher Huang Yongcheng’s tutorial! I won’t explain it in detail. If you don’t understand, just watch the video!

After integrating the upload, I found that the uploaded image path was escaped and could not be displayed, as shown in the figure:

I used the anti-escape function where the data is displayed, and operated {$article.content|stripslashes}. This way, the escaped string is anti-escaped, so that the data can be displayed normally
As shown in the picture:

Then when displaying data in the front-end template, you must not only anti-escape but also remove the html materialization, {$article.content|htmlspecialchars_decode|stripslashes}, so that it can be displayed normally!

There is another question. When the content in Baidu Editor grows, its height also grows, as shown in the picture:


The solution is to open the comment on line 428 of Ueditor's configuration file ueditor.config.js and change it to true, and open the comment on line 430 and change it to the height corresponding to your initialization. As shown in the picture:


This way the editor won’t be stretched too high! As shown in the picture:


Finished! ! ! Please don’t criticize those who say something bad~~This is just for sharing and communication. If I say something wrong, just point it out. Thank you~~~

Additional explanation: Regarding the solution to the bug that Ueditor cannot be called under ie7, this was discovered by someone when I was browsing the official website the day before yesterday, because I only have the one that everyone loves. I haven’t tested ie6 yet, so someone else reminded me to correct the bug solution for ie7 now~Thank you so much~
As shown in the picture:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/897696.htmlTechArticleThinkPHP integrates Baidu Ueditor graphic tutorial, ThinkPHP integrates Baidu Ueditor, statement based on teacher Huang Yongcheng’s video explanation: best Everyone who can write absolute paths should write absolute paths well...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

deepseek web version entrance deepseek official website entrance deepseek web version entrance deepseek official website entrance Feb 19, 2025 pm 04:54 PM

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

Baidu Apollo releases Apollo ADFM, the world's first large model that supports L4 autonomous driving Baidu Apollo releases Apollo ADFM, the world's first large model that supports L4 autonomous driving Jun 04, 2024 pm 08:01 PM

On May 15, Baidu Apollo held Apollo Day 2024 in Wuhan Baidu Luobo Automobile Robot Zhixing Valley, comprehensively demonstrating Baidu's major progress in autonomous driving over the past ten years, bringing technological leaps based on large models and a new definition of passenger safety. With the world's largest autonomous vehicle operation network, Baidu has made autonomous driving safer than human driving. Thanks to this, safer, more comfortable, green and low-carbon travel methods are turning from ideal to reality. Wang Yunpeng, vice president of Baidu Group and president of the Intelligent Driving Business Group, said on the spot: "Our original intention to build autonomous vehicles is to satisfy people's growing yearning for better travel. People's satisfaction is our driving force. Because safety, So beautiful, we are happy to see

Baidu Robin Li led a team to visit PetroChina to discuss the intelligence of the oil and gas industry Baidu Robin Li led a team to visit PetroChina to discuss the intelligence of the oil and gas industry May 07, 2024 pm 06:13 PM

According to news from this site on May 7, on May 6, Robin Li, founder, chairman and CEO of Baidu, led a team to visit China National Petroleum Corporation (hereinafter referred to as "PetroChina") in Beijing and met with directors of China National Petroleum Corporation Chairman and Party Secretary Dai Houliang held talks. The two parties had in-depth exchanges on strengthening cooperation and promoting the deep integration of the energy industry with digital intelligence. PetroChina will accelerate the construction of a digital China Petroleum Corporation, strengthen cooperation with Baidu Group, promote the in-depth integration of the energy industry with digital intelligence, and make greater contributions to ensuring national energy security. Robin Li said that the "intelligent emergence" and core capabilities of understanding, generation, logic, and memory displayed by large models have opened up a broader space for imagination for the combination of cutting-edge technology and oil and gas business. Always

Where is the thinkphp homepage file? Where is the thinkphp homepage file? Apr 09, 2024 pm 05:54 PM

The homepage file in the ThinkPHP framework is used to define the homepage of the website. It is located at app/home/controller/IndexController.php and contains an action method named index, which is responsible for processing homepage requests. This method contains the business logic of the homepage and returns the view file app/home/view/index/index.html.

See all articles