Php 如何在CI中的AWS文件夹上上载图像
我使用了下面的代码Php 如何在CI中的AWS文件夹上上载图像,php,amazon-web-services,Php,Amazon Web Services,我使用了下面的代码 //include the S3 class if (!class_exists('S3'))require_once('S3.php'); //AWS access info if (!defined('awsAccessKey')) define('awsAccessKey', '****************'); if (!defined('awsSecretKey')) define('awsSecretKey', '********
//include the S3 class
if (!class_exists('S3'))require_once('S3.php');
//AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', '****************');
if (!defined('awsSecretKey')) define('awsSecretKey', '**************************');
//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);
$s3->putBucket($bucket, S3::ACL_PUBLIC_READ);
在这里,我们在S3中放置文件夹名的地方不存在文件夹的概念。您在S3控制台中看到的文件夹只是文件夹的幻觉 由于每个对象都接受键中的
/
,因此可以模拟文件夹层次结构(即:images/myphoto.jpg
),但文件系统仍然是平面的
S3控制台为您模拟文件夹层次结构,但此概念与文件相关,因此您不能使用putBucket
,而是使用具有适当键的putObject
:
发件人:
任何错误?????请使用putObjectFile
use Aws\S3\S3Client;
$bucket = '*** Your Bucket Name ***';
$keyname = 'images/photo.jpg';
// $filepath should be absolute path to a file on disk
$filepath = '*** Your File Path ***';
// Instantiate the client.
$s3 = S3Client::factory();
// Upload a file.
$result = $s3->putObject(array(
'Bucket' => $bucket,
'Key' => $keyname,
'SourceFile' => $filepath,
'ContentType' => 'text/plain',
'ACL' => 'public-read',
'StorageClass' => 'REDUCED_REDUNDANCY',
'Metadata' => array(
'param1' => 'value 1',
'param2' => 'value 2'
)
));
echo $result['ObjectURL'];