php form表单提交 然后上传图片到七牛

来源:互联网 发布:微信推广淘宝方法 编辑:程序博客网 时间:2024/06/16 03:15
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();    }
原创粉丝点击