顯示具有 js實用套件 標籤的文章。 顯示所有文章
顯示具有 js實用套件 標籤的文章。 顯示所有文章

2018年8月13日 星期一

ckeditor + ckfinder 應用在Laravel




一.ckeditor提供編輯器功能

在view的頁面加載editor  full js

<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">

<!-- 可选的Bootstrap主题文件(一般不用引入) -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">

<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="https://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>

<script src="//cdn.ckeditor.com/4.10.0/full/ckeditor.js"></script>
<textarea id="editor1" name="editor1" cols="100" rows="30" name="update_context">

</textarea>
<script >

var editor = CKEDITOR.replace( 'editor1' );
CKFinder.setupCKEditor( editor );
</script>

二.ckfinder 
1.Laravel  下安裝 ,版本需要大於5.5 且需要extension gd等
 
composer require ckfinder/ckfinder-laravel-package
2.Run the command to download the CKFinder code.
 
php artisan ckfinder:download

3.Publish the CKFinder connector configuration and assets.
 
php artisan vendor:publish --tag=ckfinder

4.Create a directory for CKFinder files and allow for write access to it. By default CKFinder expects the files to be placed in public/userfiles (this can be altered in the configuration).
 
mkdir -m 777 public/userfiles
5.laravel config 會多出一個設定檔案
 
config/ckfinder.php
6.在view頁面引入
 
@include('ckfinder::setup')
7.上傳的圖片位置會出現在 userfiles 資料夾底下。

8.程式碼範例
 

<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">

<!-- Bootstrap主题文件(一般不用引入) -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">

<!-- jQuery文件。在bootstrap.min.js 之前引入 -->
<script src="https://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>

<script src="//cdn.ckeditor.com/4.10.0/full/ckeditor.js"></script>
@include('ckfinder::setup')
<textarea id="editor1" name="editor1" cols="100" rows="30" name="update_context">

</textarea>
<script >

var editor = CKEDITOR.replace( 'editor1' );
CKFinder.setupCKEditor( editor );
</script>


9.資料夾權限等級劃分
 (不是用laravel session  因為laravel session無法在config設定檔用)

在登入的controller控制器使用php session

//登入
Session::put('userDatas',$account);
$_SESSION['ckfinder_file'] = Session::get('userDatas');

//登出
session_destroy();

在  config/ckfinder.php 加入以下片段

//最前面
session_start();

if(isset($_SESSION['ckfinder_file'])) {

    $ckfinder_file = $_SESSION['ckfinder_file'];
} else {
    $ckfinder_file = "temp";
}

// Backend 調整

$config['backends']['default'] = array(

    'name'         => 'default',
    'adapter'      => 'local',
    'baseUrl'      => env('APP_URL').'userfiles/'.$ckfinder_file."/",
    'root'         => public_path('userfiles/').$ckfinder_file."/",
    'chmodFiles'   => 0777,
    'chmodFolders' => 0755,
    'filesystemEncoding' => 'UTF-8'

);

2018年8月11日 星期六

jQuery File Upload 檔案上傳套件 應用在laravel 紀錄

說明: https://blueimp.github.io/jQuery-File-Upload/

在Laravel框架下,因為MVC分開原因,需要做以下設定。

1.View: 引入Js,跟html語法。
  	

jQuery File Upload Demo

Basic Plus UI version


File Upload widget with multiple file selection, drag&drop support, progress bars, validation and preview images, audio and video for jQuery.
Supports cross-domain, chunked and resumable file uploads and client-side image resizing.
Works with any server-side platform (PHP, Python, Ruby on Rails, Java, Node.js, Go etc.) that supports standard HTML form file uploads.


Add files...
 

Demo Notes

  • The maximum file size for uploads in this demo is 999 KB (default file size is unlimited).
  • Only image files (JPG, GIF, PNG) are allowed in this demo (by default there is no file type restriction).
  • Uploaded files will be deleted automatically after 5 minutes or less (demo files are stored in memory).
  • You can drag & drop files from your desktop on this webpage (see Browser support).
  • Please refer to the project website and documentation for more information.
  • Built with the Bootstrap CSS framework and Icons from Glyphicons.


2.在route需要設定any方式  (讓post,get,delete.都可以通過)

Route::any('/file','HomeController@file');



3.需要加載PHP UploadHandler class,在Laravel裡面可以用composer加載
EX:放在white/tool工具資料夾,將UploadHandler檔案加入namespace,用composer dump-autoload 更新加載。
UploadHandler檔案需要做以下調整:


namespace white\tool;

class UploadHandler

{

  //public function __construct 裡面的script_url調整位置

  'script_url' => 'https://myurl/laravel55/shop55/public/file',

}
4.在加載的js裡面有一個檔案,main.js需要調整 Url設定,用來指向route設定的方法
    $('#fileupload').fileupload({
        // Uncomment the following to send cross-domain cookies:
        //xhrFields: {withCredentials: true},
        url:'https://myurl/laravel55/shop55/public/file'
    });



5.調整php.ini設定
extension=php_gd2.dll
6.錯誤說明:
-如果跳出$等jquery錯誤,可能是沒有先加入jquery的function
-刪除檔案跳出405 not method allow,可能是route沒有設定正確 (any方法,確定route對),或參考3.4路徑確定正確
-上傳跳出Filed to resize image,需要調整5 php.ini設定
-記得檔案資料夾權限要設定允許寫入跟讀取

2015年5月10日 星期日

jQuery File Upload 檔案上傳套件


jQuery File Upload 檔案上傳套件


多功能上傳管理套件,
可以一次多檔上傳,
顯示上傳進度等,功能

GitHub下載點:https://github.com/blueimp/jQuery-File-Upload/tags

步驟一:
引入下列四個檔案:





步驟二:
uploads資料夾  ->上傳檔案存放之處
ajax/upload.php   ->使用php判斷file 上傳的目錄位置 以及顯示是否上傳成功狀態
index.php ->範例程式
js/   ->引用的四個js檔案


<出處:http://blog.acoak.com/archives/73>

步驟三:
1.ajax/upload.php 程式碼:



2.index.php  程式碼:




jQuery File Upload Example
 
 
 
 .

 
 


 
拖曳至此上傳

Ckeditor 強力線上編輯程式

ckeditor 是一個很強大的上傳PHP圖文編輯器

下載的載點跟網址如下:


編輯器:CKeditor
支援語法:PHPASPASP.NETCF
檔案大小:1.99MB
元件版本:3.5.1
官方展示:http://ckeditor.com/demo
官方下載:http://ckeditor.com/download



上傳元件:CKfinder
檔案大小:1.01MB
支援語法:PHPASPASP.NETCF
元件版本:2.0.1
官方展示:http://ckfinder.com/demo 
官方下載:http://ckfinder.com/download


步驟1:
下載完畢後,將兩個檔案放在同一層資料夾 解壓縮,
建立一個upload資料夾用來放置上傳檔案的位置。

如laravel 架構:
在public/js 放置ckeditor,ckfinder 檔案,
在public/js 放置upload為上傳存放資料夾




步驟2:
在ckfinder裡面->config.php

baseurl設定上傳存放資料夾的目錄:
$baseUrl = 'http://localhost/laravel/public/js/upload/';



步驟3: 

!!!如果更改config.js 沒有效果,請關閉分頁,重新打開讓他生效!!!

在ckeditor裡面->config.js
設定瀏覽器編輯圖片功能顯示的資料夾 位置

config.filebrowserBrowseUrl = 'js/ckfinder/ckfinder.html';
config.filebrowserImageBrowseUrl = 'js/ckfinder/ckfinder.html?Type=Images';
config.filebrowserFlashBrowseUrl = 'js/ckfinder/ckfinder.html?Type=Flash';
config.filebrowserUploadUrl = 'js/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files'; //可上傳一般檔案
config.filebrowserImageUploadUrl = 'js/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';//可上傳圖檔
config.filebrowserFlashUploadUrl = 'js/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';//可上傳Flash檔案



步驟4:
在ckeditor裡面->config.js檔案,可以設定編輯器的功能

 //全功能
 config.toolbar_Full = [
    ['Source','-','Save','NewPage','Preview','-','Templates'],
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
    ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
    ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
    '/',
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
     ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
     ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
     ['Link','Unlink','Anchor'],
    ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
    '/',
     ['Styles','Format','Font','FontSize'],
     ['TextColor','BGColor']
 ];




 config.js 所設定的編輯器參數如下


工具列參數列表:
'Source':原始碼
'Save':儲存
'NewPage':開新檔案
'Preview':預覽
'Templates':樣版

'Cut':剪下
'Copy':複製
'Paste':貼上
'PasteText':貼為文字格式
'PasteFromWord':從word 貼上
'Print':列印
'SpellChecker':拼字檢查
'Scayt':即時拼寫檢查

'Undo':上一步
'Redo':重作
'Find':尋找
'Replace':取代
'SelectAll':全選
'RemoveFormat':清除格式

'Form':表單
'Checkbox':核取方塊
'Radio':單選按鈕
'TextField':文字方塊
'Textarea':文字區域
'Select':選單
'Button':按鈕
'ImageButton':影像按鈕
'HiddenField':隱藏欄位

'Bold':粗體
'Italic':斜體
'Underline':底線
'Strike':刪除線
'Subscript':下標
'Superscript':上標
'NumberedList':編號清單
'BulletedList':項目清單
'Outdent':減少縮排
'Indent':增加縮排
'Blockquote':引用文字

'JustifyLeft':靠左對齊
'JustifyCenter':置中
'JustifyRight':靠右對齊
'JustifyBlock':左右對齊

'Link':超連結
'Unlink':移除超連結
'Anchor':錨點

'Image':圖片影像
'Flash':Flash
'Table':表格
'HorizontalRule':水平線
'Smiley':表情符號
'SpecialChar':特殊符號
'PageBreak':分頁符號

'Styles':樣式
'Format':格式
'Font':字體
'FontSize':大小

'TextColor':文字顏色
'BGColor':背景顏色

'Maximize':最大化
'ShowBlocks':顯示區塊
'About':關於CKEditor