You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.0 KiB
95 lines
3.0 KiB
<?php
|
|
/**
|
|
* 上传附件和上传视频
|
|
* User: Jinqn
|
|
* Date: 14-04-09
|
|
* Time: 上午10:17
|
|
*/
|
|
include "Uploader.class.php";
|
|
|
|
/* 上传配置 */
|
|
$base64 = "upload";
|
|
switch (htmlspecialchars($_GET['action'])) {
|
|
case 'uploadimage':
|
|
$config = array(
|
|
"pathFormat" => $CONFIG['imagePathFormat'],
|
|
"maxSize" => $CONFIG['imageMaxSize'],
|
|
"allowFiles" => $CONFIG['imageAllowFiles']
|
|
);
|
|
$fieldName = $CONFIG['imageFieldName'];
|
|
break;
|
|
case 'uploadscrawl':
|
|
$config = array(
|
|
"pathFormat" => $CONFIG['scrawlPathFormat'],
|
|
"maxSize" => $CONFIG['scrawlMaxSize'],
|
|
"allowFiles" => $CONFIG['scrawlAllowFiles'],
|
|
"oriName" => "scrawl.png"
|
|
);
|
|
$fieldName = $CONFIG['scrawlFieldName'];
|
|
$base64 = "base64";
|
|
break;
|
|
case 'uploadvideo':
|
|
$config = array(
|
|
"pathFormat" => $CONFIG['videoPathFormat'],
|
|
"maxSize" => $CONFIG['videoMaxSize'],
|
|
"allowFiles" => $CONFIG['videoAllowFiles']
|
|
);
|
|
$fieldName = $CONFIG['videoFieldName'];
|
|
break;
|
|
case 'uploadfile':
|
|
default:
|
|
$config = array(
|
|
"pathFormat" => $CONFIG['filePathFormat'],
|
|
"maxSize" => $CONFIG['fileMaxSize'],
|
|
"allowFiles" => $CONFIG['fileAllowFiles']
|
|
);
|
|
$fieldName = $CONFIG['fileFieldName'];
|
|
break;
|
|
}
|
|
|
|
/* 生成上传实例对象并完成上传 */
|
|
$up = new Uploader($fieldName, $config, $base64);
|
|
$file_data = $up->getFileInfo();
|
|
/**
|
|
* 得到上传文件所对应的各个参数,数组结构
|
|
* array(
|
|
* "state" => "", //上传状态,上传成功时必须返回"SUCCESS"
|
|
* "url" => "", //返回的地址
|
|
* "title" => "", //新文件名
|
|
* "original" => "", //原始文件名
|
|
* "type" => "" //文件类型
|
|
* "size" => "", //文件大小
|
|
* )
|
|
*/
|
|
|
|
// 上传到OSS代码
|
|
if (!$_SERVER['REQUEST_SCHEME']) {
|
|
$protocol = $_SERVER['SERVER_PORT'] == 443 ? "https" : "http";
|
|
} else {
|
|
$protocol = $_SERVER['REQUEST_SCHEME'];
|
|
}
|
|
$ch = curl_init();
|
|
// 阿里云OSS上传
|
|
curl_setopt($ch, CURLOPT_URL, $protocol.'://'.$_SERVER['HTTP_HOST'].'/base/oss/admin/Oss/ossload');
|
|
// 腾讯云COS上传
|
|
//curl_setopt($ch, CURLOPT_URL, $protocol.'://'.$_SERVER['HTTP_HOST'].'/base/cos/admin/File/ueditorFileUploadToCos');
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
|
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
|
|
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, [
|
|
// 图片地址
|
|
'url'=>$file_data['url']
|
|
]);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
$result = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
$result = json_decode($result, true);
|
|
|
|
$file_data['url'] = $result['data']['url'];
|
|
|
|
/* 返回数据 */
|
|
return json_encode($file_data);
|