Blogger Information
Blog 14
fans 0
comment 0
visits 12036
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Thinkphp3.2整合阿里云OSS图片上传
alber1986的博客
Original
787 people have browsed it

Thinkphp3.2整合阿里云OSS图片上传,图片上传至OSS可减少服务器压力,节省宽带,安全又稳定,阿里云OSS对于做负载均衡非常方便,不用传到各个服务器了

33333.jpg

首先引入阿里云OSS类库

<?php 
 
namespace Home\Controller; 
 
use Think\Controller; 
use OSS\Core\OssException; 
 
vendor('aliyun.autoload');

上传图片自己写,上传成功到阿里云后,删除临时文件

function aliyun() { 
        $bucket = "ssxxx"; 
        $accessKeyId = "QlmCSuHgoxZNKCb"; //去阿里云后台获取秘钥 
        $accessKeySecret = "JQWc9Coh5R0Fke936kQNwUrorh "; //去阿里云后台获取秘钥 
        $endpoint = "http://oss-cn-hangzhou.aliyuncs.com/"; //你的阿里云OSS地址 
        $ossClient = new \OSS\OssClient($accessKeyId, $accessKeySecret, $endpoint); 
//        判断bucketname是否存在,不存在就去创建 
        if (!$ossClient->doesBucketExist($bucket)) { 
            $ossClient->createBucket($bucket); 
        } 
 
 
        $object = "sucaihuo.jpg"; //想要保存文件的名称 
        $file = "logo.jpg"; //文件路径,必须是本地的。 
//        $file = "./Uploads/Uploads/2017-07-24/5975c17ec4d9d.jpg"; 
        try { 
            $ossClient->uploadFile($bucket, $object, $file); 
             unlink($file); 
        } catch (OssException $e) { 
            $e->getErrorMessage(); 
        } 
    }

本实例下载:https://www.sucaihuo.com/php/3846.html

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post