我在脚本中有这段代码,它按预期运行,但是当我放入一个基本的 CodeIgniter 模型来运行它时,我得到一个 500 错误。我已将其范围缩小到“使用 Aws\S3\S3Client”以及所有使用“使用”功能的行。我对命名空间非常陌生,不知道从哪里开始。这是代码:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Dev_model extends CI_Model {
public function aws()
{
require_once('AWSSDKforPHP/aws.phar');
use Aws\S3\S3Client;
use Aws\Common\Enum\Region;
use Aws\Common\Aws;
use Aws\S3\Enum\CannedAcl;
use Aws\S3\Exception\S3Exception;
use Guzzle\Http\EntityBody;
//get the $s3 object
$config = array(
'key' => 'XXXXXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
'region' => Region::US_EAST_1
);
$s3 = S3Client::factory($config);
try {
$test = file_get_contents("http://www.nasa.gov/images/content/711375main_grail20121205_4x3_946-710.jpg");
$result = $s3->putObject(array(
'Bucket' => 'mybucket',
'Key' => "picture.jpg",
'Body' => $test
));
echo 'complete';
} catch (S3Exception $e) {
echo 'error';
}
}
}