顯示具有 php 標籤的文章。 顯示所有文章
顯示具有 php 標籤的文章。 顯示所有文章

2019年8月23日 星期五

gcp centos7 laravel

說明:https://www.brilliantcode.net/170/centos-7-install-apache-httpd/


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

sudo passwd root

安裝 EPEL

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

1.安裝Apache and http模組

sudo yum install httpd mod_ssl openssl

啟動Apache,並且設定為開機自動啟動

sudo systemctl start httpd
sudo systemctl enable httpd


確認Apache執行權限
sudo vim /etc/httpd/conf/httpd.conf

更改
User apache
Group apache
(因為會有FTP檔案上傳問題,可以改成自己的user )

設定或修改Apache目錄

sudo vim /etc/httpd/conf/httpd.conf

顯示:
DocumentRoot "/var/www/html"



讓Apache可以支援.htaccess,請加入AllowOverride All


<directory "/var/www/html">
    AllowOverride All
</Directory>


存檔離開
:wq

重啟APACHE
sudo systemctl start httpd

Selinux 安全性說明
https://www.brilliantcode.net/145/centos-7-check-selinux-status-enabled-or-not/

暫時停止SELinux
sudo setenforce 0

暫時啟動SELinux
sudo setenforce 1

sudo vim /etc/selinux/config

永久停止SELinux:將第6行改為SELINUX=disable
永久啟用SELinux:將第6行改為SELINUX=enable

開啟防火牆,讓 web (port:80, 443) 流量可以穿過 firewall

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

重啟Apache服務
sudo systemctl restart httpd.service

2. install mysqld

sudo yum -y install mariadb-server

安全性服務+設定密碼
mysql_secure_installation

3.PHP 安裝 7.2

yum -y install mod_php72w php72w-cli php72w-common php72w-gd php72w-imap php72w-ldap php72w-mbstring php72w-mysql php72w-pdo php72w-pear php72w-xml php72w-xmlrpc

重啟
systemctl restart httpd.service

4.安裝 Composer

複製安裝文件 PHP 檔案
執行安裝 composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

 php composer-setup.php

完成以後,我們要放到全域環境,這樣才能讓任何專案無須從新安裝 composer。記得 Composer 限制不可在最高權限 root 中執行。

mv composer.phar /usr/local/bin/composer

5.安裝 phpMyAdmin

.用 composer 下載 (建議,因為版本最新,解決許多問題)

chmod 777 /var/www/html  <-- 提供寫入權限給 composer 建立路徑

cd /var/www/html
composer create-project phpmyadmin/phpmyadmin

cp -i /var/www/html/phpmyadmin/config.sample.inc.php /var/www/html/phpmyadmin/config.inc.php

GCP登入方式

http://zxcvbnm2749.blogspot.com/2018/07/ssh-ftp-google-cloud.html

6.git安裝

sudo rpm -U https://centos7.iuscommunity.org/ius-release.rpm sudo yum install git2u
sudo yum install git2u

7.權限問題


在對應資料夾下使用此指令
chcon -R -t httpd_sys_rw_content_t 我的專案名稱/storage


CentOS 對內部檔案的權限管理非常嚴謹,當其他使用者在看網頁時,CentOS 內其實是有一名叫做 apache 的使用者在瀏覽您的網頁目錄,雖然如此但 apache 也不是什麼檔案都能看,僅能觀看httpd 相關權限的檔案而已,在還沒修改網站權限時你可以透過 ls -Z 來取得目前的權限。


但是 httpd_sys_content_t 僅是瀏覽的權限而已,依據 laravel 的安裝說明bootstrap/cache 及 storage 這兩個資料夾必須要有寫入的權限,所以需再做以下修改:




1
2
3
4
$ chcon -Rv -t httpd_sys_rw_content_t blog/storage
$ chcon -Rv -t httpd_sys_rw_content_t blog/bootstrap/cache
$ sudo chmod -R 777 blog/storage
$ sudo chmod -R 777 blog/bootstrap/cache


2018年8月29日 星期三

laravel voyager 教學

說明:https://github.com/the-control-group/voyager

中文化這邊有:https://laravel-china.org/topics/4720/i-also-translated-laravels-background-extension-voyager


1.首先安裝laravel 5.5

composer create-project laravel/laravel 5.5

composer update

2.安裝voyager

composer require tcg/voyager

3.設定env
APP_URL=http://localhost:8000
DB_DATABASE=xxxx
DB_USERNAME=xxxx
DB_PASSWORD=xxxx

4.執行voyager install migrate

php artisan voyager:install

PS:如果出現錯誤可以到config/databases 調整mysql

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'unix_socket' => env('DB_SOCKET', ''),
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix' => '',
    'strict' => true,
    'engine' => null,
],


3.創建admin

php artisan voyager:admin your@email.com --create


5.網址打入 localhost:8000/admin 使用剛剛輸入的密碼登入


6.設定可以使用google analytics功能

說明:https://www.youtube.com/watch?v=Qw5HQiZIehg

在setting頁面->admin->

Google Analytics Client ID (used for admin dashboard) setting('admin.google_analytics_client_id')

填入https://console.developers.google.com/apis/dashboard
設定的 oauth 憑證的client_id。

設定完畢即可以在disable登入gmail帳號,並看到相關數據資料。




2018年8月15日 星期三

Laravel hide whoops error

在設定Laravel錯誤時候,
會設定DEBUG方便偵錯,

APP_ENV=local
APP_DEBUG=true

但是DEBUG時候再Woops錯誤時候會顯示ENV DB帳密等資訊,

可以藉由調整Laravel底下的 config/app.php來避免顯示過多的
調整以下限制會在Whoops輸出錯誤資訊時候,將對應的帳密等ENV設定顯示****

1.全部阻擋
'debug_blacklist' => [
        // '_COOKIE' => array_keys($_COOKIE),
        '_SERVER' => array_keys($_SERVER),
        '_ENV' => array_keys($_ENV),        
    ],
2.阻擋顯示指定的參數
'debug_blacklist' => [
        '_ENV' => [
            'APP_KEY',
            'DB_PASSWORD',
            'REDIS_PASSWORD',
            'MAIL_PASSWORD',
            'PUSHER_APP_KEY',
            'PUSHER_APP_SECRET',
        ],
        '_SERVER' => [
            'APP_KEY',
            'DB_PASSWORD',
            'REDIS_PASSWORD',
            'MAIL_PASSWORD',
            'PUSHER_APP_KEY',
            'PUSHER_APP_SECRET',
        ],
        '_POST' => [
            'password',
        ],
    ], 

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年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月10日 星期四

laravel class not found 問題

在laravel5 不管新增加什麼控制器/model 有用到classmap
請先打composer dump-autoload

避免出現class not found

2018年5月6日 星期日

Larvel4.2 升級到5.0 5.2一些備註

larvel 升級的說明:


(一) 4.2升級到5.0

https://laravel.tw/docs/5.0/upgrade

大升級有幾個操作上文件沒有說到的部份要注意:

1.執行composer update時候出錯,

需要將vendor/compiled.php 移除,在重新執行composer update

2.注意控制器的命名空間問題

將所有的控制器移到 app/Http/Controllers 目錄下。既然在本指南中我們不打算整合到完整的命名空間,請將 app/Http/Controllers 添加到 composer.json 的 classmap,接下來,您可以從 app/Http/Controllers/Controller.php 基底抽象類別中移除命名空間,並確認整合過來的控制器是繼承這個基底類別。
在 app/Providers/RouteServiceProvider.php 檔案中,將 namespace 屬性設定為 null

3.注意CSRF問題

預設情況下,所有路由都會使用 CSRF 保護。若想關閉它們,或是只在特定路由開啟,請移除 App\Http\Kernel 中 middleware 陣列內的這一行:
'App\Http\Middleware\VerifyCsrfToken',

4.移除Form 跟 Html功能 要使用需要以下調整:

(1)在composer.json  裡面

 require 追加
        "laravelcollective/html": "~5.0"

使用composer update 更新

(2) config/app.php檔案裡面調整

 'providers' 追加     
        'Collective\Html\HtmlServiceProvider',

'aliases' 追加
        'Form' => 'Collective\Html\FormFacade',
        'Html' => 'Collective\Html\HtmlFacade',


(二) 4.2升級到5.2

https://laravel.tw/docs/5.0/upgrade

1.注意Input功能消失,要使用需要在 config/app.php檔案裡面調整:


 This commit removed Input facade definition from config/app.phphence you have to manually add that in to aliases array as below,
'Input' => Illuminate\Support\Facades\Input::class,
Or You can import Input facade directly as required,
use Illuminate\Support\Facades\Input;














2018年5月1日 星期二

Laravel controller,model更改目錄

laravel 4底下
預設controller目錄 app/controller
預設model目錄 app/model

如果要在兩個目錄底下在放資料夾,在資料夾底下放對應的controller,model 做法如下: 

app/controller/player 
app/model/player 

修改composer.json 檔案
在autoload追加classmap
 

"autoload": {
  "classmap": [
   "app/commands",
   "app/controllers",
   "app/controllers/player",
   "app/models",
   "app/models/player",
   "app/database/migrations",
   "app/database/seeds",
   "app/tests/TestCase.php"
  ]
 },



 調整完畢後,使用指令
composer dump-autoload

 原因:
 因為 database 文件夾使用 classmap 來做加載的。所以只有在打了composer dump-autoload之後  composer 才會更新 autoload_classmap 的內容。

2018年2月17日 星期六

laravel homestead

 參考教學:
https://laravel.tw/docs/4.2/homestead
https://blog.wu-boy.com/2014/09/get-homestead-vagrant-vm-running/

一. 安裝
1. Vagrant Installer
https://www.vagrantup.com/downloads.html
2. Virtual Box
https://www.virtualbox.org/wiki/Downloads
3. git tool
http://git-scm.com/downloads

二. 下指令下載vagrant box 的laravel/homestead
$ vagrant box add laravel/homestead

三. 安裝homestead
$ git clone https://github.com/laravel/homestead.git Homestead

四. 打開.Homestead資料夾,底下的Homestead.yaml 設定對應

ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: C:\Users\zxcvbnm2749\Code
      to: /home/vagrant/Code

sites:
    - map: homesteadwhite
      to: /home/vagrant/Code/public
databases:
    - homestead

五. 設定電腦host的對應網址

http://192.168.10.10/     homesteadwhite

六. 啟動vagrant up

cd目錄到homestead資料夾,執行指令,就可以成功啟動機器
vagrant up

七. vagrant 指令

vagrant 開機
vagrant up
vagrant 關機
vagrant halt
vagrant ssh登入
vagrant ssh

八. 連入資料庫方法
因為vagrant預設連入DB是使用內建的mysql:homestead資料庫
DB:localhost
port:33060
帳號:homestead
密碼:secret
設定在laravel的 app\config\local\database.php
如果要更改成自己本機的mysql需要調整此設定檔
   'mysql' => array(
   'driver'    => 'mysql',
   'host'      => '59.127.xxx.xxx',
   'database'  => 'white',
   'username'  => 'xxxx',
   'password'  => 'xxxx',
   'charset'   => 'utf8',
   'collation' => 'utf8_unicode_ci',
   'prefix'    => '',
  ),














2015年5月17日 星期日

驗證碼


驗證碼分成三個部分,
A test.php  主頁面顯示驗證碼輸入 跟刷新按鈕
B image.php 產出亂數的圖片,並存入session
C check.php 驗證圖片跟輸入的值是否符合

需注意 在IE 下如點選驗證碼無刷新,
需要再按鈕跟圖片網址加上變數如 時間,
這樣每次刷新網址的參數會變,
避免IE如相同圖片會有暫存無刷新。

1. test.php    主頁面顯示驗證碼輸入 跟刷新按鈕


Check 

2.image.php     產出亂數的圖片,並存入session


ob_start();
session_start();
header('content-Type:image/gif');
echo mt_srand(time());
$randval = mt_rand();
$seccode = substr($randval,-4);
$length = strlen($seccode);
$_SESSION['seccode'] = $seccode; //用SESSION保存驗證碼
$img=imagecreate(80,30);
$black = ImageColorAllocate($img, 0,0,0);
$white = ImageColorAllocate($img, 255,255,255);
$gray = ImageColorAllocate($img, 200,200,200);
imagefill($img,0,0,$gray);

for($i=0;$i<200;$i++) //加入干擾象素
{
$randcolor = ImageColorallocate($img,rand(10,250),rand(10,250),rand(10,250));
imagesetpixel($img,rand()%90,rand()%30,$randcolor);
}

for ($i = 0; $i < $length; $i++) {
$color = imagecolorallocate($img,abs(mt_rand()%256),abs(mt_rand()%256),abs(mt_rand()%256));
imagechar($img,20,abs(mt_rand()%4)+$i*15,abs(mt_rand()%5),$seccode[$i],$color);
}
imagegif($img);
imageDestroy($img);
ob_end_flush();


3.check.php 驗證圖片跟輸入的值是否符合

session_start();
if($_POST['imgCode']==$_SESSION['seccode'])
echo '驗證成功';
else
echo '驗證失敗';

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



2015年5月7日 星期四

FB Oauth2 授權登入-part2 ( php寫法)

設定完 FB APP 的資料後,
即可以開始使用PHP撰寫 FB Oauth登入。


code部分如下:


 
<?php 
$app_id = "xxxxxxxxxxxxxxxxxxx";      //FB APP的 ID
$app_secret = "xxxxxxxxxxxxxxxxxxx";  //FB APP的 Secret
$my_url = "http://localhost:8000/fb.php";  // 驗證完畢來redirect的網址
 
session_start();
if(isset($_REQUEST["code"]))
{
  $code = $_REQUEST["code"];    //返回的oauth 授權 返回code驗證資訊 
}

 
if(empty($code)) {
 $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
 $dialog_url = "https://www.facebook.com/v2.12/dialog/oauth?client_id=".$app_id."&redirect_uri=".$my_url."&state=".$_SESSION['state'].'&scope=user_birthday,email,user_friends'."&response_type=code";
 echo  $dialog_url;
 echo "<br>"."<br>";
}  
 

if(isset($code)) {

    $token_url = "https://graph.facebook.com/v2.12/oauth/access_token?"."client_id=".$app_id."&redirect_uri=".$my_url."&client_secret=".$app_secret."&code=".$code;
    echo $code;
    echo "<br>"."<br>";

    $curl = curl_init($token_url);
    curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $response = curl_exec($curl);
    echo var_dump($response);
    $response = json_decode($response);
    echo var_dump($response);
    echo "<br>"."<br>";
    curl_close($curl);

    $graph_url = "https://graph.facebook.com/v3.0/me?access_token="
      . $response->access_token."&fields=id,name,gender,friends";
    
    $curl = curl_init($graph_url);
    curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $user_data = curl_exec($curl);

    print_r($user_data);
    $user_data = json_decode($user_data);
    $user = $user_data->id;
    $url = "http://graph.facebook.com/".$user_data->id."/picture?type=large";
    $name = $user_data->name;   
    echo "使用者ID:".$user."</p><p>";
    echo "使用者url:".$url."</p><p>";
    echo "臉書名稱:".$name."</p><p>";
   }
else
{
    echo("顯示錯誤,請從正確網址進入");
    
}
 
?>
 

?>