Donnie
Donnie

Reputation: 6351

S3 SDK Breaking my site

My problem:

require_once '/includes/aws-sdk-1.5.2/sdk.class.php';

My environment: I have a pretty standard PHP site that uses __autoload() to grab any classes that I need. However, I now need to include the SDK to send files over to S3, but simply requiring that library seems to throw off the scope of the entire app so that any code that follows is broken.

Example:

// Save to S3
require_once '/var/www/html/system/aws-sdk-1.5.2/sdk.class.php';

$s3 = new AmazonS3();

if( ! $s3->if_bucket_exists(S3_BUCKET) )
    throw new Exception('S3 bucket does not exist.');


$response = $s3->create_object(S3_BUCKET, $temp_file['s_unique_name'], array(
    'fileUpload' => $_FILES['my_file']['tmp_name'],
    'acl'        => $s3::ACL_PUBLIC
));

// Save file
$photo = new vehicle_photo();
$photo->i_vehicle = $i_vehicle;
$photo->s_file    = $temp_file['s_url'];
$photo->s_label   = $_FILES['my_file']['name'];
$photo->save();

So, with the // Save to S3 snippet enabled, the following vehicle_photo class can no longer be found, in addition to all other classes that may be used after this point. If I disable it, everything works.

What's happening here?

Upvotes: 1

Views: 192

Answers (1)

user1233508
user1233508

Reputation:

Sounds like the autoloading mechanisms are conflicting. You might find this helpful: https://forums.aws.amazon.com/thread.jspa?threadID=85239 . Additionally, spl_autoload_register is better than plain old __autoload - consider migrating your autoloader code to that.

Upvotes: 4

Related Questions