php上传七牛云 发表于 2016-08-23 | 更新于 2023-01-11 首先下载qiniu_sdk到本地… 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748<?phpini_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']; }}