设置 AWS S3 和 Codeigniter
Settingup AWS S3 and Codeigniter
我需要将 Amazon S3 与 CI3 一起使用,所以我的计划是制作一个名为 AmazonS3 的库,我将在其中使用 up()
delete()
tokenize()
举个例子。
我在 application/s3 目录中使用 composer 安装了 S3。
**我图书馆的代码:**
<?php
defined('BASEPATH') OR exit('u no here!');
use Aws\S3\S3Client;
class AmazonS3 {
private $s3;
private $bucket;
function __construct()
{
$this->bucket = 'images.secret.com';
require 'application/s3/vendor/autoload.php';
$this->s3 = S3Client::factory([
'key' => 'super-key---',
'secret' => 'thats-a-long-string'
]);
}
public function up()
{
$this->s3->putObject([
'Bucket' => $this->bucket,
'Key' => 'images/test.jpg',
'Body' => fopen('application/img/test.jpg', 'rb'),
'ACL' => 'public-read'
]);
}
}
这个 up() 方法只是一个测试目的,我从另一个控制器调用它的方式是这样的:
$this->load->library('amazons3');
$this->amazons3->up();
这给了我几吨的错误。我缺少什么?
好的,我找到了解决方案,这不是 codeigniter 问题,我缺少出厂设置的区域部分!
我需要将 Amazon S3 与 CI3 一起使用,所以我的计划是制作一个名为 AmazonS3 的库,我将在其中使用 up()
delete()
tokenize()
举个例子。
我在 application/s3 目录中使用 composer 安装了 S3。
**我图书馆的代码:**
<?php
defined('BASEPATH') OR exit('u no here!');
use Aws\S3\S3Client;
class AmazonS3 {
private $s3;
private $bucket;
function __construct()
{
$this->bucket = 'images.secret.com';
require 'application/s3/vendor/autoload.php';
$this->s3 = S3Client::factory([
'key' => 'super-key---',
'secret' => 'thats-a-long-string'
]);
}
public function up()
{
$this->s3->putObject([
'Bucket' => $this->bucket,
'Key' => 'images/test.jpg',
'Body' => fopen('application/img/test.jpg', 'rb'),
'ACL' => 'public-read'
]);
}
}
这个 up() 方法只是一个测试目的,我从另一个控制器调用它的方式是这样的:
$this->load->library('amazons3');
$this->amazons3->up();
这给了我几吨的错误。我缺少什么?
好的,我找到了解决方案,这不是 codeigniter 问题,我缺少出厂设置的区域部分!