Commit 82458740 by 李洋

替换ueditor的PHP文件夹

parent c1e41f57
<?php
use OSS\OssClient; // OSS客户端类
use OSS\Core\OssException; // OSS异常类
$path = preg_replace('/public/', '', $_SERVER['DOCUMENT_ROOT']);
require_once $path.'/vendor/OSS/autoload.php';
/**
* Created by JetBrains PhpStorm.
......@@ -107,19 +113,80 @@ class Uploader
}
//创建目录失败
if (!file_exists($dirname) && !mkdir($dirname, 0777, true)) {
$this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR");
return;
} else if (!is_writeable($dirname)) {
$this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE");
return;
// if (!file_exists($dirname) && !mkdir($dirname, 0777, true)) {
// $this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR");
// return;
// } else if (!is_writeable($dirname)) {
// $this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE");
// return;
// }
// 上传到OSS
$accessKeyId = 'LTAIEIrl7ZgNVagi';
$accessKeySecret = 'I14efjgfLXpWtHhfdDO77LrFkeSkPA';
$endPoint = 'http://oss-cn-shenzhen.aliyuncs.com';
$bucket = 'ichunt-img';
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endPoint);
$fileType = $this->fileType($file['type']);
$object = $fileType.'/cms/'.$this->fullName;
$result = $ossClient->uploadFile($bucket, $object, $file["tmp_name"]);
// 上传返回
if (isset($result) && $result['info']['http_code'] == 200) {
$this->stateInfo = $this->stateMap[0];
} else {
$this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE");
}
//移动文件
if (!(move_uploaded_file($file["tmp_name"], $this->filePath) && file_exists($this->filePath))) { //移动失败
$this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE");
} else { //移动成功
$this->stateInfo = $this->stateMap[0];
// if (!(move_uploaded_file($file["tmp_name"], $this->filePath) && file_exists($this->filePath))) { //移动失败
// $this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE");
// } else { //移动成功
// $this->stateInfo = $this->stateMap[0];
// }
}
/**
* 文件类型
* @param [String] $fileType [MIME]
* @return [String]
*/
public function fileType($fileType)
{
switch ($fileType) {
case 'image/jpeg':
case 'image/png':
case 'image/gif':
case 'image/bmp':
return 'images';
break;
case 'application/msword':
return 'documet';
break;
case 'application/vnd.ms-excel':
return 'excel';
break;
case 'application/vnd.ms-powerpoint':
return 'ppt';
break;
case 'application/pdf':
return 'pdf';
break;
case 'text/plain';
return 'txt';
break;
case 'video/avi':
case 'application/vnd.rn-realmedia-vbr':
// case 'application/octet-stream':
return 'video';
break;
default:
return $this->_json(403, '暂时不支持此文件类型上传');
break;
}
}
......@@ -341,8 +408,10 @@ class Uploader
public function getFileInfo()
{
//分配正确路径
$urlroot = explode('Public/plugin/editor/php', $_SERVER['PHP_SELF']);
$urlroot = $urlroot[0] . 'Uploads/';
// $urlroot = explode('Public/plugin/editor/php', $_SERVER['PHP_SELF']);
// $urlroot = $urlroot[0] . 'Uploads/';
$urlroot = 'http://img.ichunt.com/images/cms/';
return array(
"state" => $this->stateInfo,
......
......@@ -25,8 +25,13 @@ if (isset($_POST[$fieldName])) {
$source = $_GET[$fieldName];
}
foreach ($source as $imgUrl) {
$item = new Uploader($imgUrl, $config, "remote");
$info = $item->getFileInfo();
if(strstr($imgUrl,'img.ichunt.com')===FALSE){
$item = new Uploader($imgUrl, $config, "remote");
$info = $item->getFileInfo();
}else $info=[
'state'=>'SUCCESS',
'url'=>$imgUrl
];
array_push($list, array(
"state" => $info["state"],
"url" => $info["url"],
......
......@@ -5,6 +5,7 @@
* Date: 14-04-09
* Time: 上午10:17
*/
include "Uploader.class.php";
/* 上传配置 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment