require_once APP_ROOT.'/vendor/config.php';
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;//引入上传类
/*
$name 上传图片的名字 :$_FILES['file']['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();
}
Submit the php form form and upload the image to Qiniu
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325818611&siteId=291194637
Recommended
Ranking