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();
}
Upload a single file from the server directly to Qiniu
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325722131&siteId=291194637
Recommended
Ranking