ThinkPHP 5+Uuditor画像をアリクラウドオブジェクトストレージOSSにアップロード
ThinkPHP 5リッチテキストUuditorを使用して、リッチテキスト編集ボックス内にローカルの画像をアップロードし、アリクラウドオブジェクトストレージOSSに変更する
ThinkPHP 5ロードUuditor・・・略
Ueditorのダウンロード:https://ueditor.baidu.com/website/download.html#ueditorアリクラウドオブジェクトストレージSDKダウンロード:https://github.com/aliyun/aliyun-oss-php-sdk
一、構成項目ueditorディレクトリ:publicstaticadminlibueditor1.4.3 OSSプロファイルディレクトリ:アプリケーションconfigoos.php OSS SDKディレクトリ:extendoos
二、コード1、OSSプロファイル
2.Uuditorの下にOosを書き込む.class.phpコントローラ*注:本人は相対パスを使用していますので、自分のディレクトリ構造に合わせてファイル導入アドレスを置き換えてください
3、Uuditorがアップロードした画像のPHPファイルを修正し、publicstaticadminlibueditor1.4.3\php\action_crawler.php
ThinkPHP 5ロードUuditor・・・略
Ueditorのダウンロード:https://ueditor.baidu.com/website/download.html#ueditorアリクラウドオブジェクトストレージSDKダウンロード:https://github.com/aliyun/aliyun-oss-php-sdk
一、構成項目ueditorディレクトリ:publicstaticadminlibueditor1.4.3 OSSプロファイルディレクトリ:アプリケーションconfigoos.php OSS SDKディレクトリ:extendoos
二、コード1、OSSプロファイル
'xxxx',
'accessKeyId' => 'xxxxxxxxxxx',
'accessKeySecret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
'bucket' => 'xxxxx',
'uploadurl' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // ,
];
2.Uuditorの下にOosを書き込む.class.phpコントローラ*注:本人は相対パスを使用していますので、自分のディレクトリ構造に合わせてファイル導入アドレスを置き換えてください
oos === null){
$config = require realpath(dirname(__FILE__) . '/../../../../../../../') .'/application/config/oos.php';
$this->bucket = $config['bucket'];
try {
$this->oos = new OssClient($config['accessKeyId'], $config['accessKeySecret'], $config['endpoint'], false);
} catch (OssException $e) {
printf(__FUNCTION__ . "creating OssClient instance: FAILED
");
printf($e->getMessage() . "
");
return null;
}
}
return $this->oos;
}
//
public function upload($file,$save){
$config = require realpath(dirname(__FILE__) . '/../../../../../../../') .'/application/config/oos.php';
$save = 'upload/'.$save;
$ossClient = $this->getOssClient();
if (is_null($ossClient)) exit(' ');
$result = $ossClient->uploadFile($this->bucket, $save, $file);
return !empty($result['x-oss-request-id']);
}
}
3、Uuditorがアップロードした画像のPHPファイルを修正し、publicstaticadminlibueditor1.4.3\php\action_crawler.php
$CONFIG['catcherPathFormat'],
"maxSize" => $CONFIG['catcherMaxSize'],
"allowFiles" => $CONFIG['catcherAllowFiles'],
"oriName" => "remote.png"
);
$fieldName = $CONFIG['catcherFieldName'];
/* */
$list = array();
if (isset($_POST[$fieldName])) {
$source = $_POST[$fieldName];
} else {
$source = $_GET[$fieldName];
}
foreach ($source as $imgUrl) {
$item = new Uploader($imgUrl, $config, "remote");
$info = $item->getFileInfo();
$year = date('Ymd',time());// ( / )
$img_name = time().rand(1,1000).$info['type'];
$bos_url = "ueditor_upload/xinjieshi/image/$year/$img_name";//
$oos->upload($_SERVER['DOCUMENT_ROOT'].'/'.$info['url'],$bos_url);
array_push($list, array(
"state" => $info["state"],
"url" => $oos_config['uploadurl'].$bos_url,
"size" => $info["size"],
"title" => htmlspecialchars($info["title"]),
"original" => htmlspecialchars($info["original"]),
"source" => htmlspecialchars($imgUrl)
));
}
/* */
return json_encode(array(
'state'=> count($list) ? 'SUCCESS':'ERROR',
'list'=> $list
));