搜尋
首頁後端開發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 27, 2025 am 12:23 AM

tomodifyDataNaphPsession,startTheSessionWithSession_start(),然後使用$ _sessionToset,修改,orremovevariables.1)startThesession.2)setthesession.2)使用$ _session.3)setormodifysessessvariables.3)emovervariableswithunset()

舉一個在PHP會話中存儲數組的示例。舉一個在PHP會話中存儲數組的示例。Apr 27, 2025 am 12:20 AM

在PHP會話中可以存儲數組。 1.啟動會話,使用session_start()。 2.創建數組並存儲在$_SESSION中。 3.通過$_SESSION檢索數組。 4.優化會話數據以提升性能。

垃圾收集如何用於PHP會議?垃圾收集如何用於PHP會議?Apr 27, 2025 am 12:19 AM

PHP會話垃圾回收通過概率機制觸發,清理過期會話數據。 1)配置文件中設置觸發概率和會話生命週期;2)可使用cron任務優化高負載應用;3)需平衡垃圾回收頻率與性能,避免數據丟失。

如何在PHP中跟踪會話活動?如何在PHP中跟踪會話活動?Apr 27, 2025 am 12:10 AM

PHP中追踪用戶會話活動通過會話管理實現。 1)使用session_start()啟動會話。 2)通過$_SESSION數組存儲和訪問數據。 3)調用session_destroy()結束會話。會話追踪用於用戶行為分析、安全監控和性能優化。

如何使用數據庫存儲PHP會話數據?如何使用數據庫存儲PHP會話數據?Apr 27, 2025 am 12:02 AM

利用數據庫存儲PHP會話數據可以提高性能和可擴展性。 1)配置MySQL存儲會話數據:在php.ini或PHP代碼中設置會話處理器。 2)實現自定義會話處理器:定義open、close、read、write等函數與數據庫交互。 3)優化和最佳實踐:使用索引、緩存、數據壓縮和分佈式存儲來提升性能。

簡單地說明PHP會話的概念。簡單地說明PHP會話的概念。Apr 26, 2025 am 12:09 AM

phpsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIdStoredInAcookie.here'showtomanageThemeffectionaly:1)startAsessionWithSessionWwithSession_start()和stordoredAtain $ _session.2)

您如何循環中存儲在PHP會話中的所有值?您如何循環中存儲在PHP會話中的所有值?Apr 26, 2025 am 12:06 AM

在PHP中,遍歷會話數據可以通過以下步驟實現:1.使用session_start()啟動會話。 2.通過foreach循環遍歷$_SESSION數組中的所有鍵值對。 3.處理複雜數據結構時,使用is_array()或is_object()函數,並用print_r()輸出詳細信息。 4.優化遍歷時,可採用分頁處理,避免一次性處理大量數據。這將幫助你在實際項目中更有效地管理和使用PHP會話數據。

說明如何使用會話進行用戶身份驗證。說明如何使用會話進行用戶身份驗證。Apr 26, 2025 am 12:04 AM

會話通過服務器端的狀態管理機制實現用戶認證。 1)會話創建並生成唯一ID,2)ID通過cookies傳遞,3)服務器存儲並通過ID訪問會話數據,4)實現用戶認證和狀態管理,提升應用安全性和用戶體驗。

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

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),