I am attempting to upload a file to s3 using php 5.3.3. I am using the Amazon PHP sdk and using the autoloader. The problem is that the autoloader for AWS is not loading the classes correctly and we are getting a exception when loading S3. Our server structure looks like this:
->public (www document root)
->lib
->->aws
So our upload code is located in /public/ and our AWS library is located at /lib/aws/ so to get from public to lib we do /../lib/aws/.
Here is what the upload.php code looks like in the public folder which initiates the amazon upload:
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' => '******'
));
It successfully works and prints the echo 'creating...' output and then we get an error.
Here is what the exception looks like:
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 )
We are using the latest version of AWS from: https://github.com/aws/aws-sdk-php
We are using PHP 5.3.3 and also the flourishlib: http://flourishlib.com/
That also has a flourishlib autoload function which looks like this:
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');
I think what is happening is the flurishlib autoload function is trying to load the amazon classes and its causing a error.
How can I make amazon use the correct autoload function?