我正在尝试使用 php 5.3.3 将文件上传到 s3。我正在使用 Amazon PHP sdk 并使用自动加载器。问题是 AWS 的自动加载器没有正确加载类,我们在加载 S3 时遇到异常。我们的服务器结构如下所示:
->public(www 文档根目录)
->库
->->aws
因此,我们的上传代码位于 /public/ 中,而我们的 AWS 库位于 /lib/aws/ 中,因此为了从 public 到 lib,我们执行 /../lib/aws/。
以下是启动亚马逊上传的公用文件夹中的 upload.php 代码:
require $_SERVER['DOCUMENT_ROOT'].'/../lib/aws/aws-autoloader.php';
use Aws\Common\Aws;
use Aws\S3\Exception\S3Exception;
echo 'creating...';
$s3 = S3Client::factory(array(
'key' => '****',
'secret' => '******'
));
它成功地工作并打印了 echo 'creating...' 输出,然后我们得到一个错误。
这是异常的样子:
2014-04-12 19:46:40 UTC creating...
2014-04-12 19:46:40 UTC ( Exception Object
2014-04-12 19:46:40 UTC [message:protected] => The class S3Client could not be loaded
2014-04-12 19:46:40 UTC [string:Exception:private] =>
2014-04-12 19:46:40 UTC [code:protected] => 0
2014-04-12 19:46:40 UTC [file:protected] => /public/upload.php
2014-04-12 19:46:40 UTC [line:protected] => 26
2014-04-12 19:46:40 UTC [trace:Exception:private] => Array
2014-04-12 19:46:40 UTC (
2014-04-12 19:46:40 UTC [0] => Array
2014-04-12 19:46:40 UTC (
2014-04-12 19:46:40 UTC [function] => __autoload
2014-04-12 19:46:40 UTC [args] => Array
2014-04-12 19:46:40 UTC (
2014-04-12 19:46:40 UTC [0] => S3Client
2014-04-12 19:46:40 UTC )
2014-04-12 19:46:40 UTC
2014-04-12 19:46:40 UTC )
2014-04-12 19:46:40 UTC
2014-04-12 19:46:40 UTC [1] => Array
2014-04-12 19:46:40 UTC (
2014-04-12 19:46:40 UTC [file] => /public/upload.php
2014-04-12 19:46:40 UTC [line] => 15
2014-04-12 19:46:40 UTC [function] => spl_autoload_call
2014-04-12 19:46:40 UTC [args] => Array
2014-04-12 19:46:40 UTC (
2014-04-12 19:46:40 UTC [0] => S3Client
2014-04-12 19:46:40 UTC )
2014-04-12 19:46:40 UTC
2014-04-12 19:46:40 UTC )
2014-04-12 19:46:40 UTC
2014-04-12 19:46:40 UTC [2] => Array
2014-04-12 19:46:40 UTC (
2014-04-12 19:46:40 UTC [file] => /public/upload.php
2014-04-12 19:46:40 UTC [line] => 408
2014-04-12 19:46:40 UTC [args] => Array
2014-04-12 19:46:40 UTC (
2014-04-12 19:46:40 UTC [0] => /public/upload.php
2014-04-12 19:46:40 UTC )
2014-04-12 19:46:40 UTC
2014-04-12 19:46:40 UTC [function] => include
2014-04-12 19:46:40 UTC )
2014-04-12 19:46:40 UTC
2014-04-12 19:46:40 UTC )
2014-04-12 19:46:40 UTC
2014-04-12 19:46:40 UTC [previous:Exception:private] =>
2014-04-12 19:46:40 UTC )
我们正在使用最新版本的 AWS: https ://github.com/aws/aws-sdk-php
我们正在使用 PHP 5.3.3 和繁荣库:http: //flourishlib.com/
这也有一个像这样的繁荣库自动加载功能:
function __autoload($class_name)
{
// Customize this to your root Flourish directory
$flourish_root = $_SERVER['DOCUMENT_ROOT'].'/../lib/flourishlib/';
$file = $flourish_root . $class_name . '.php';
if (file_exists($file)) {
include $file;
return;
}
throw new Exception('The class ' . $class_name . ' could not be loaded');
}
spl_autoload_register('__autoload');
我认为发生的事情是flurishlib自动加载功能正在尝试加载亚马逊类并导致错误。
如何让亚马逊使用正确的自动加载功能?