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月12日 星期日

Laravel apache alias mod Rewrite 設定

有一個固定IP,但在資料夾底下有多個專案,需要重新改向路徑。

1.httpd.conf設定

 
LoadModule rewrite_module modules/mod_rewrite.so

需要拿掉註解#啟用
2.在httpd.conf 增加對應資料夾別名
 

Alias /shop55 "C:/website/www/laravel55/shop55/public"
<Directory "C:/website/www/laravel55/shop55/public">
</Directory>

Alias /white55 "C:/website/www/laravel55/white55/public"
<Directory "C:/website/www/laravel55/white55/public">
</Directory>


3.在對應的專案資料夾public下需要新增 .htaccess檔案 並寫入RewriteBase /Alias name

舉例:white55下的 C:/website/www/laravel55/white55/public

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /white55
</IfModule>

4.重啟apache

 
c:\Apache24\bin\httpd -k restart

5.額外問題,用main當路徑會有導向失敗的問題?,用mainIndex就沒問題?

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設定
-記得檔案資料夾權限要設定允許寫入跟讀取

2018年7月10日 星期二

SSH登入 + FTP登入 google cloud說明

照這篇做可以使用FTP連線登入
https://sammy197.tw/4061/%E5%9C%A8gcp%EF%BC%88google-cloud-platform%EF%BC%89%E4%B8%8A%E9%80%8F%E9%81%8Eftp%E4%B8%8A%E5%82%B3%E6%AA%94%E6%A1%88/

權限設定請參考這篇
http://xtony77.logdown.com/posts/209067-ubuntu-notes-using-ssh-key-login

如果要用cmder使用密碼連入。

可以在Server上設定 ssh的允許密碼登入方式

cd /ctc/ssh
vi sshd_config

PasswordAuthentication yes 
PermitRootLogin yes
UsePrivilegeSeparation no

重新啟動
service ssh restart

在Server上需要設定root帳號

第一次設定root帳號需要打入密碼

sudo passwd root

輸入密碼,設定完畢。

--------------------------------------------------------------------------------------------------

在本地端的cmder使用
ssh root@ip

輸入root的密碼 就可以登入囉!


PS:如果出現Permission denied (publickey)
P請注意ssh資料夾的權限是否設定正確,不能設定成777

1.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

2.
home/使用者/.ssh
chmod 600 ~/.ssh/authorized_keys

記得重啟
service ssh restart

2018年6月6日 星期三

Redis 安裝教學

在window下使用Redis
文章:http://www.runoob.com/redis/redis-install.html
文章:https://www.xiabingbao.com/php/2017/08/27/window-php-redis.html


1.到redis下載版本 並解壓縮
https://github.com/MicrosoftArchive/redis/releases

本次下載的是 C:\website\Redis-x64-3.2.100


2.CD到Redis目錄
//利用 Redis Desktop Manager 查看資料
//1.啟動
redis-server.exe redis.windows.conf

開啟另一個服務窗 

//2.連入redis

redis-cli -h host -p port -a password

redis-cli -h 127.0.0.1 -p 6379 -a "mypass"

redis-cli

//3.設定值
set myKey abc


//4.取得值
get myKey

PHP使用Redis擴展方法

一樣使用上面安裝Redis-x64-3.2.100

1.下載php ext擴展dll

php_igbinary.dll和php_redis.dll
(1) php_igbinary.dll: php_igbinary-2.0.1-5.6-ts-vc11-x64.zip
https://windows.php.net/downloads/pecl/releases/igbinary/2.0.1/

(2).php_redis.dll:php_redis-2.2.7-5.6-ts-vc11-x64.zip
https://windows.php.net/downloads/pecl/releases/redis/2.2.7/

2.將兩個dll檔案放到php/ext下,並在php.ini 追加以下兩條

extension=php_igbinary.dll
extension=php_redis.dll

3.重啟apache
c:\Apache24\bin\httpd -k restart

4.創建一個test.php檔案,測試是否擴展成功
phpinfo();

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo "Connection to server sucessfully";
echo "Server is running: " . $redis->ping();


畫面上應該會顯示phpinfo()確定是不是有redis資訊且顯示
Connection to server sucessfullyServer is running: +PONG

2018年5月23日 星期三

Laravel呼叫方法

說明:https://stackoverflow.com/questions/28573860/laravel-requestall-should-not-be-called-statically/28574081

輔助方法:https://docs.laravel-dojo.com/laravel/5.2/helpers

1. static方法
use Request;

public static function test(Request $request)
{ 
    $data= Request::all();
}


2.  一般方法
use Illuminate\Http\Request;

public static function test(Request $request)
{
   $age = \Request::input('age');
   $data = $request->all();
}



3.輔助方法

use Illuminate\Http\Request;

public static function test(Request $request)
{
    $data= request()->all();
}



2018年5月21日 星期一

mysql常用指令

Mysql需要啟動服務

cd到mysql bin底下有mysql執行檔的地方

1.安裝
mysqld install

2.啟動服務
net start mysql

3.停止服務
net stop mysql

4.mysql 遠端連線  -u:mysql account   -h:ip   -P:port
mysql -uroot -p -hlocalhost -P33600

進入 mysql> 底下下指令

1.顯示DB
show databases;

2.使用databases mydatabase
use mydatabase;

3.查詢 task 底下的tabel mytable
select * from mytable;

4.顯示資料庫中的所有table
 show tables from mytable;

5.顯示資料表的結構
desc mytable;

6.顯示狀態
status;