✏️ 正在编辑: S3.php
路径:
/srv/systems_dir/yuppiecred/library/Core/Amazon/S3.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php require 'aws.phar'; use Aws\S3\S3Client; use Aws\S3\Exception\S3Exception; use Guzzle\Http\Client; use Aws\S3\Enum\Permission; use Aws\S3\Enum\Group; use Aws\S3\Model\AcpBuilder; class Core_Amazon_S3 { private $_accessKey; private $_secretKey; private $_s3; private $_bucketName; public function __construct() { $this->getConfigurations(); $this->_s3 = S3Client::factory(array( 'key' => $this->_accessKey, 'secret' => $this->_secretKey )); } public function getConfigurations() { //teste local $config = new Zend_Config_Ini(APPLICATION_PATH . "/configs/configuracoes.ini"); //usuário final // $config = new Zend_Config_Ini(CLIENT_PATH . "/configs/configuracoes.ini"); $this->_accessKey = $config->production->s3->access_key; $this->_secretKey = $config->production->s3->secret_key; $this->_bucketName = $config->production->s3->bucket_name; } public function createBucket($bucketName) { try { $this->_s3->createBucket(array('ACL' => 'private', 'Bucket' => $bucketName)); } catch ( S3Exception $e ) { return $e->getMessage(); } } public function getObject($object) { try { return $this->_s3->getObject(array( 'Bucket' => $this->_bucketName, 'Key' => $object )); } catch ( S3Exception $e ) { echo $e->getMessage(); } } public function getObjectUrl($uri, $lifetime = "+1 minutes") { try { $http = new Client(); $signedUrl = $this->_s3->getObjectUrl($this->_bucketName, $uri, $lifetime); $response = $http->get($signedUrl)->send(); return $response->getBody(); } catch ( S3Exception $exc ) { echo $exc->getMessage(); } } public function putObject($fileName, $localPath) { try { $result = $this->_s3->putObject(array( 'ACL' => 'authenticated-read', 'Bucket' => $this->_bucketName, 'Key' => $fileName, 'SourceFile' => $localPath )); return $result['ObjectURL']; } catch ( Zend_Service_Amazon_S3_Exception $e ) { return $e->getMessage(); } } public function getObjectsByBucket() { try { return $this->_s3->getObjectsByBucket(array('Bucket' => $this->_bucketName)); } catch ( Zend_Service_Amazon_S3_Exception $e ) { return $e->getMessage(); } } public function getInfo($name) { try { return $this->_s3->getInfo($name); } catch ( Zend_Service_Amazon_S3_Exception $e ) { return $e->getMessage(); } } public function deleteObject($file) { try { return $this->_s3->deleteObject(array('Bucket' => $this->_bucketName, 'Key' => $file)); } catch ( Zend_Service_Amazon_S3_Exception $e ) { return $e->getMessage(); } } public function removeBucket() { try { return $this->_s3->removeBucket($this->_bucketName); } catch ( Zend_Service_Amazon_S3_Exception $e ) { return $e->getMessage(); } } public function isValidBucketName($bucketName) { return $this->_s3->isValidBucketName($bucketName); } public function clearBucket($bucketName) { return $this->clearBucket($bucketName); } }
💾 保存文件
← 返回文件管理器