-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
37 lines (28 loc) · 1.02 KB
/
upload.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
!defined('DEBUG') AND exit('Access Denied.');
function uploadfile($path){
require("Qiniu/autoload.php");
//require 'plugin/gmchina_xiuno_editormd/upload/qiniu/Qiniu/src/Qiniu/Auth.php';
$config = include("config.php");
$mimetype=explode(",", str_replace(array(",",';',';'," "),",",$config['mimetype']));
$ext= pathinfo($path, PATHINFO_EXTENSION);
if(in_array($ext, $mimetype) == false) {
return false;
}else{
$key =md5(date('YmdHis') . rand(0, 9999)) . '.' . $ext;
$accessKey = $config['accessKey'];
$secretKey = $config['secretKey'];
$auth = new Qiniu\Auth($accessKey, $secretKey);
$bucket = $config['bucket'];
$domain = $config['cdnurl'];
$token = $auth->uploadToken($bucket);
$uploadMgr = new Qiniu\Storage\UploadManager();
list($ret, $err) = $uploadMgr->putFile($token, $key, $path);
if ($err !== null) {
return false;
}else {
return $domain.'/'.$ret['key'];
}
}
}
?>