• ThinkPHP 阿里云图片上传


    public function abing(Request $request){
            if($request->isPost()){
          //composer require aliyuncs/oss-sdk-php $file = $request->file('filed'); $accessKeyId = "LTAI4FpYGu9bgnf"; $accessKeySecret = "K9rN5hPMYu4RW3VyKxNg"; // Endpoint以杭州为例,其它Region请按实际情况填写。 $endpoint = "http://oss-cn-shanghai.aliyuncs.com"; // 存储空间名称 $bucket= "abing9"; // <yourObjectName>上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg $info = $file->move(ROOT_PATH.'public'.DS.'uploads'); $path = $info->getSaveName(); $content = ROOT_PATH.'public'.DS.'uploads/'.$path; $object = $info->getFilename(); try { $ossClinet = new OssClient($accessKeyId,$accessKeySecret,$endpoint); $res = $ossClinet->uploadFile($bucket,$object,$content); print_r($res['info']['url']);//这里可以单独处理下异常 }catch (OssException $exception){ print_r($exception); } }else{ echo 3333; return $this->fetch(); } }

      图片处理文档:https://help.aliyun.com/document_detail/47735.html?spm=a2c4g.11186623.6.1090.29fa1329s237Sx

    以下不经过本地保存

    public function abing(Request $request){
            if($request->isPost()){
               $file = $request->file('filed');
                $accessKeyId = "LTAI4FpYnf";
                $accessKeySecret = "K9rN5h";
                // Endpoint以杭州为例,其它Region请按实际情况填写。
                $endpoint = "http://oss-cn-shanghai.aliyuncs.com";
                // 存储空间名称
                //https://help.aliyun.com/document_detail/47735.html?spm=a2c4g.11186623.6.1090.29fa1329s237Sx
                $bucket= "abing9";
                $info = $file->getInfo();
                $object = rand(1000,9999).'.png';  //文件名
                $content = $info['tmp_name'];//文件内容
                try {
                    $ossClinet = new OssClient($accessKeyId,$accessKeySecret,$endpoint);
                    $res = $ossClinet->uploadFile($bucket,$object,$content);
                    print_r($res['info']['url']);
                }catch (OssException $exception){
                    print_r($exception);
                }
    
    
            }else{
                return $this->fetch();
            }
        }

     阿里云视频点播上传视频文件如下:

    public function video(Request $request){
            //if($request->isPost()){
                require_once ROOT_PATH.'vendoraliyuncsaliyun-php-sdk-coreConfig.php';
                require_once ROOT_PATH."vendoraliyuncsAutoloader.php";
    
                $accessKeyId = "LTAI49bgnf";
                $accessKeySecret = "K9rN55uyKxNg";
                $regionId = 'cn-shanghai';
    
                try {
                    $uploader = new AliyunVodUploader($accessKeyId,$accessKeySecret);
                    $uploadVideoRequest = new UploadVideoRequest('D:	estsample.mp4','estUploadWebVideo via PHP-SDK');
                    $uploadVideoRequest->setTitle('mytitle');//会生成视频的名称
    
                    $res = $uploader->uploadLocalVideo($uploadVideoRequest);
                    var_dump('生成的ID编号为'.$res); //返回一大片.生成视频唯一ID的字符串
    
                }catch (Exception $e){
                    print_r($e->getMessage());
                }
        }
  • 相关阅读:
    Maven学习
    Android屏幕适配
    Java多线程中的死锁问题[转]
    数据结构基本概念和算法分析
    AsyncTask(异步任务)
    Android自定义滑动开关按钮
    记录一些我记不住的技术
    2017携程Web前端实习生招聘笔试题总结
    JavaScript ES5面向对象实现一个todolist
    原生JavaScript实现一个简单的todo-list
  • 原文地址:https://www.cnblogs.com/bing2017/p/12392222.html
Copyright © 2020-2023  润新知