require_once APP_ROOT.'/vendor/config.php';
use Qiniu\Storage\UploadManager;
//$name 原文件名 $filePath文件本地路径 也可是$_FILES["file"]["tmp_name"];
function postDoupload($name,$filePath){
$filetype = explode('.',$name);//获取文件扩展名 防止有的手机不支持七牛
$accessKey =Config::AK;
$secretKey = Config::SK;
$bucket = Config::BUCKET_IMG_NAME;
// 构建鉴权对象
$auth = new Auth($accessKey, $secretKey);
// 生成上传 Token
$token = $auth->uploadToken($bucket);
// 要上传文件的本地路径
$filePath = $filePath;
// 上传到七牛后保存的文件名
$key =time().mt_rand(1,1000).".".$filetype[1];
// 初始化 UploadManager 对象并进行文件的上传。
$uploadMgr = new UploadManager();
// 调用 UploadManager 的 putFile 方法进行文件的上传。
list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
$url=Config::IMG_DOMAIN.$ret['key'];
return $url;die();
}
服务器单文件直接上传到七牛
最新推荐文章于 2024-07-08 17:32:00 发布