我試圖上傳一個文件到s3使用PHP 5.3.3。我正在使用Amazon PHP sdk並使用自動加載器。問題在於AWS的自動加載器不能正確加載類,並且在加載S3時出現異常。我們的服務器結構如下:亞馬遜php sdk和flourishlib自動加載器s3client無法加載
- >公共網站(www文檔根目錄)
- > LIB
- > - > AWS
所以我們上傳的代碼位於/公/和我們的AWS庫位於/ lib/aws /中,以便從公共目錄獲取到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' => '******'
));
它成功地運作並打印回聲「創建......」輸出,然後我們得到了一個錯誤。
這裏是例外的樣子:
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,也是flourishlib: http://flourishlib.com/
這也有一個flourishlib自動加載功能,看起來像這樣:
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 autoload函數試圖加載亞馬遜類,並導致錯誤。
如何讓亞馬遜使用正確的自動加載功能?
那麼__autoload函數沒有被自動註冊,這就是爲什麼在底部我們有spl_autoload_register函數。調用它__自動加載沒有區別我認爲。 – pppglowacki