七牛云图片上传和审核

发布时间:2022-06-29 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了七牛云图片上传和审核脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
//接收文件上传的值$file = $_FILES;//本地的文件路径$localFilePath = $file['file']['tmp_name'];//截取文件后缀名//$suffix = '.jpg';$suffix = strtolower(substr($file['file']['name'],strpos($file['file']['name'],'.')));//生成一个唯一的文件名称,重命名 (md5加密原文件名+秒+随机数)$fileName = md5($file['file']['name']) . date('s',time()) . rand(1,9999999);$fileName .= $suffix;//上传七牛云业务逻辑$accessKey = ''; //去控制台的秘钥管理拿AK$secretKey = '';//去控制台的秘钥管理拿SK//七牛云桶名,根据自己实际进行填写$bucket = '';//图片违规验证$url = 'http://ai.qiniuapi.com/v3/image/censor';$method="POST";$host="ai.qiniuapi.com";$contentType = 'application/json';//图片地址$image_url='https://www.gaopinimages.com/img/newLogo_back_white.bd2c2e64.png';$scenes = [    'censor' => ['pulp', 'terror', 'politician', 'ads'],    'pulp' => ['pulp'],    'terror' => ['terror'],    'politician' => ['politician'],    'ads' => ['ads']];$body = [    'data' => ['uri' => $image_url],    'params' => ['scenes' => $scenes['censor']]];$auth = new Auth($accessKey, $secretKey);$headers=$auth->authorizationV2($url,$method,json_encode($body),$contentType);$headers['Content-type']=$contentType;$headers['Host']=$host;$response=Client::post($url,json_encode($body),$headers);// 生成上传Token$token = $auth->uploadToken($bucket);// 构建 UploadManager 对象$uploadMgr = new UploadManager();// 调用 UploadManager 的 putFile 方法进行文件的上传。list($ret, $err) = $uploadMgr->putFile($token, $fileName, $localFilePath);//错误信息提示if ($err != null) {    //可调整为错误页面    $this->error('上传文件失败');}//把七牛云图片路径存储到我们自己的数据库  七牛云图片路径$imageUrl = 'http://qtpud69oi.hn-bkt.clouddn.com/' . $fileName;//入库业务逻辑 create save 只有这两个模型方法才能自动写入时间戳$result =BannerModel::create([    'image_url'=>$imageUrl,]);$this->success('上传文件成功');

脚本宝典总结

以上是脚本宝典为你收集整理的七牛云图片上传和审核全部内容,希望文章能够帮你解决七牛云图片上传和审核所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:数据库