搜索
首页后端开发php教程CKEditor图片上传功能开启方法_PHP教程

CKEditor图片上传功能开启方法_PHP教程

Jul 13, 2016 pm 05:49 PM
cckeditorphp上传功能图片开启怎么方法编辑器

PHP怎么给ckeditor编辑器加上传图片的功能?CKEditor官方演示是有上传图片和浏览服务器文件功能的,但是我们自己下载回来的却没有这两个功能……

其实还需要下载另外一个组件:CKFinder,用它配合CKEditor来实现上传功能。

官方提供了PHP,Asp.Net和Asp三个语言版本的CKFinder,下载地址:http://ckfinder.com/download

将CKFinder解压缩到网站目录。调用方法如下(假设CKFinder在网站根目录,可以使用相对路径):

 

CKEDITOR.replace(  'editor1',
{
filebrowserBrowseUrl :  '/ckfinder/ckfinder.html',
filebrowserImageBrowseUrl :  '/ckfinder/ckfinder.html?Type=Images',
filebrowserFlashBrowseUrl :  '/ckfinder/ckfinder.html?Type=Flash',
filebrowserUploadUrl :  '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
filebrowserImageUploadUrl  :  '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
filebrowserFlashUploadUrl  :  '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
});

同时默认情况下是禁止上传的,还需要打开CKFinder目录下的config.php,将第32行的return  false;修改为return true;

这里就是上传权限的认证了,你可以注意到上面有一大段英文注释,意思是不要简单的将它修改为return  true,而是加上例如session验证等等,否则会很危险……

下面是官方文档,关于如何增加文件上传功能,给英文好的同学参考,上面说的方法其实就是下文中的Example  5:

Basic Configuration
The filebrowserBrowseUrl setting is the  location of an external file browser, that should be launched when "Browse  Server" button(1) is pressed.

The filebrowserUploadUrl setting is the  location of a script that handles file uploads. If set, the "Upload" tab(2) will  appear in dialog boxes (only where such functionality is available, i.e. in  "Link", "Image" and "Flash" dialog windows).

Example 1 
CKEDITOR.replace( 'editor1', {
filebrowserBrowseUrl :  '/browser/browse.php',
filebrowserUploadUrl : '/uploader/upload.php',
}); 
It is also possible to set a separate url for a selected dialog box, using  the dialog name in file browser settings: filebrowser[dialogName]BrowseUrl and  filebrowser[dialogName]UploadUrl.

For example to set a special upload  url for the image dialog, set the filebrowserImageUploadUrl property: 

Example 2
CKEDITOR.replace( 'editor1', {
filebrowserBrowseUrl :  '/browser/browse.php',
filebrowserImageBrowseUrl :  '/browser/browse.php?type=Images'
filebrowserUploadUrl :  '/uploader/upload.php',
filebrowserImageUploadUrl :  '/uploader/upload.php?type=Images'
});
In the example above,  filebrowserBrowseUrl and filebrowserUploadUrl settings will be used by default,  however in the Image dialog box, CKEditor will use filebrowserImageBrowseUrl and  filebrowserImageUploadUrl configuration settings instead.

File Browser  Window Size The default width of file browser window in CKEditor is set to 80%  of screen width, the default hight is set to 70% of screen height. If for some  reasons, the default values are not suitable for you, you can change it to any  other value.

Use filebrowserWindowWidth to change width and  filebrowserWindowHeight to change height of the window.

To set the size  of the window in pixels, just set the number value (e.g. "800"). If you prefer  to set height and width of the window in percentage of the screen, remember to  add percent sign at the end (e.g. "60%").

Example 3 
CKEDITOR.replace( 'editor1', {
filebrowserBrowseUrl :  '/browser/browse.php',
filebrowserUploadUrl :  '/uploader/upload.php',
filebrowserWindowWidth :  '640',
filebrowserWindowHeight : '480',
});
To set the window size of  file browser inside of a specific dialog box, use  filebrowser[dialogName]WindowWidth and filebrowser[dialogName]WindowHeight  settings.

For example, to change the file browser window size only in  "Image" dialog box, change set the filebrowserImageWindowWidth and  filebrowserImageWindowHeight settings.

Example 4
CKEDITOR.replace(  'editor1', {
filebrowserBrowseUrl :  '/browser/browse.php',
filebrowserUploadUrl :  '/uploader/upload.php',
filebrowserImageWindowWidth :  '640',
filebrowserImageWindowHeight : '480',
});

Using  CKFinder
CKFinder may be easily integrated with CKEditor (see live demo). 

The integration may be done in two ways: by setting CKEditor  configuration options (example below) or using the CKFinder.SetupCKEditor()  method available in CKFinder API.

Example 5
CKEDITOR.replace(  'editor1',
{
filebrowserBrowseUrl :  '/ckfinder/ckfinder.html',
filebrowserImageBrowseUrl :  '/ckfinder/ckfinder.html?Type=Images',
filebrowserFlashBrowseUrl :  '/ckfinder/ckfinder.html?Type=Flash',
filebrowserUploadUrl :  '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
filebrowserImageUploadUrl  :  '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
filebrowserFlashUploadUrl  :  '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
});
The  example above is valid for PHP environment. /ckfinder/ is a base path to the  CKFinder installation directory. If your using CKFinder for ASP, ASP.NET or  ColdFusion remember to change "php" to the right extension:

asp  - CKFinder for ASP
aspx – CKFinder for ASP.NET
cfm – CKFinder for  ColdFusion
php – CKFinder for PHP

Example 6
CKEditor +  CKFinder integration with the use of CKFinder.SetupCKEditor() function: 

var editor = CKEDITOR.replace( 'editor1' );
CKFinder.SetupCKEditor(  editor, '/ckfinder/' );
The second parameter of the SetupCKEditor() method is  the path to the CKFinder installation.

Please check the  _samples/js/ckeditor.html sample distributed with CKFinder to see the full  working example of this integration method.


摘自 顺子网络

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478343.htmlTechArticlePHP怎么给ckeditor编辑器加上传图片的功能?CKEditor官方演示是有上传图片和浏览服务器文件功能的,但是我们自己下载回来的却没有这两个功...
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
哪些常见问题会导致PHP会话失败?哪些常见问题会导致PHP会话失败?Apr 25, 2025 am 12:16 AM

PHPSession失效的原因包括配置错误、Cookie问题和Session过期。1.配置错误:检查并设置正确的session.save_path。2.Cookie问题:确保Cookie设置正确。3.Session过期:调整session.gc_maxlifetime值以延长会话时间。

您如何在PHP中调试与会话相关的问题?您如何在PHP中调试与会话相关的问题?Apr 25, 2025 am 12:12 AM

在PHP中调试会话问题的方法包括:1.检查会话是否正确启动;2.验证会话ID的传递;3.检查会话数据的存储和读取;4.查看服务器配置。通过输出会话ID和数据、查看会话文件内容等方法,可以有效诊断和解决会话相关的问题。

如果session_start()被多次调用会发生什么?如果session_start()被多次调用会发生什么?Apr 25, 2025 am 12:06 AM

多次调用session_start()会导致警告信息和可能的数据覆盖。1)PHP会发出警告,提示session已启动。2)可能导致session数据意外覆盖。3)使用session_status()检查session状态,避免重复调用。

您如何在PHP中配置会话寿命?您如何在PHP中配置会话寿命?Apr 25, 2025 am 12:05 AM

在PHP中配置会话生命周期可以通过设置session.gc_maxlifetime和session.cookie_lifetime来实现。1)session.gc_maxlifetime控制服务器端会话数据的存活时间,2)session.cookie_lifetime控制客户端cookie的生命周期,设置为0时cookie在浏览器关闭时过期。

使用数据库存储会话的优点是什么?使用数据库存储会话的优点是什么?Apr 24, 2025 am 12:16 AM

使用数据库存储会话的主要优势包括持久性、可扩展性和安全性。1.持久性:即使服务器重启,会话数据也能保持不变。2.可扩展性:适用于分布式系统,确保会话数据在多服务器间同步。3.安全性:数据库提供加密存储,保护敏感信息。

您如何在PHP中实现自定义会话处理?您如何在PHP中实现自定义会话处理?Apr 24, 2025 am 12:16 AM

在PHP中实现自定义会话处理可以通过实现SessionHandlerInterface接口来完成。具体步骤包括:1)创建实现SessionHandlerInterface的类,如CustomSessionHandler;2)重写接口中的方法(如open,close,read,write,destroy,gc)来定义会话数据的生命周期和存储方式;3)在PHP脚本中注册自定义会话处理器并启动会话。这样可以将数据存储在MySQL、Redis等介质中,提升性能、安全性和可扩展性。

什么是会话ID?什么是会话ID?Apr 24, 2025 am 12:13 AM

SessionID是网络应用程序中用来跟踪用户会话状态的机制。1.它是一个随机生成的字符串,用于在用户与服务器之间的多次交互中保持用户的身份信息。2.服务器生成并通过cookie或URL参数发送给客户端,帮助在用户的多次请求中识别和关联这些请求。3.生成通常使用随机算法保证唯一性和不可预测性。4.在实际开发中,可以使用内存数据库如Redis来存储session数据,提升性能和安全性。

您如何在无状态环境(例如API)中处理会议?您如何在无状态环境(例如API)中处理会议?Apr 24, 2025 am 12:12 AM

在无状态环境如API中管理会话可以通过使用JWT或cookies来实现。1.JWT适合无状态和可扩展性,但大数据时体积大。2.Cookies更传统且易实现,但需谨慎配置以确保安全性。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器