1

I had this code in a script and it ran just as intended but then when I put into a basic CodeIgniter Model to run it I get a 500 error. I have narrowed it down to the "use Aws\S3\S3Client" and all of the lines that use the "use" function. I am very unfamiliar with namespaces and am not sure where to start here. Here is the code:

<?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';
        }
    }
}
stuyam
  • 9,561
  • 2
  • 21
  • 40

1 Answers1

0

Maybe a problem with the autoloader, i encountered a simmilar problem with restler where spl_auload_unregister was called by the framework.

You should also try using the absolute names by prefixing with \, like "use \Aws\S3\S3Client"