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 38 39 40 41 42 43 44 45 46 47 48
|
<?php ini_set('display_errors', 'On'); error_reporting(E_ALL);
require_once __DIR__ . '/../../upload/qiniu_sdk/autoload.php';
$filePath = __DIR__ . '/temp';
// 引入鉴权类 use QiniuAuth;
// 引入上传类 use QiniuStorageUploadManager;
function upload() { global $filePath; $file = $_FILES['file']; $fileName = $file['name'];
$extension = substr($fileName, strrpos($fileName, '.')); $path = $filePath . $extension;
$flag = move_uploaded_file($file['tmp_name'], $path);
if (!$file || !$flag) { die('接受文件失败'); }
$accessKey = '***'; $secretKey = '***'; $bucket = 'luzhongkuan';
$auth = new Auth($accessKey, $secretKey);
$token = $auth->uploadToken($bucket);
$uploadMgr = new UploadManager();
$key = time() . $extension;
list($ret, $err) = $uploadMgr->putFile($token, $key, $path); if ($err) { die($err); } else { return 'http://qiniu.kuan1.top/' . $ret['key']; } }
|
近期评论