如何在CakePHP 2.0.4中上传文件

时间:2011-12-05 23:44:17

标签: amazon-s3 cakephp-2.0

我尝试了2-3个插件才能使用上传功能。我想将照片上传到S3。我无法与他们中的任何人一起做。哪个插件是2.0.4版的最佳插件?

3 个答案:

答案 0 :(得分:2)

如果没有任何已针对2.0更新的插件,我建议您自己更新一个或使用GitHub上的amazon-s3-php-class。这是一个活跃的项目,需要您将课程放在供应商目录中。

要导入:

App::import(‘vendor’, ‘S3’);

使用您的配置进行实例化:

$S3 = new S3($accessKey, $secretKey);

答案 1 :(得分:0)

我觉得最好的解决方案是这个插件 http://milesj.me/code/cakephp/uploader#transfering-files-to-amazon-s3 每个蛋糕项目使用2年,它就像一个魅力,易于配置和强大的

答案 2 :(得分:-1)

文件夹放置在指定位置,例如:project-folder/vendors

导入:

function uploadToS3()
    {
      if(!empty($this->request->data))
      {
        $data = $this->request->data;

        // Import Vendor
        App::import('Vendor', '/s3/S3');

        //AWS access info
        if (!defined('awsAccessKey')) 
           define('awsAccessKey', 'Change Here');

        if (!defined('awsSecretKey')) 
           define('awsSecretKey', 'Change Here');

        //instantiate the class
        $s3 = new S3(awsAccessKey, awsSecretKey);

        $s3->putObjectFile($data[$model]['file']['tmp_name'], "bucket", 
                           'destination'.$data[$model]['file']['name'],
                           S3::ACL_PUBLIC_READ);

      }
    }
相关问题