当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Service_Amazon_S3类代码示例

本文整理汇总了PHP中Zend_Service_Amazon_S3的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Service_Amazon_S3类的具体用法?PHP Zend_Service_Amazon_S3怎么用?PHP Zend_Service_Amazon_S3使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Zend_Service_Amazon_S3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: isValid

 public function isValid($data)
 {
     $valid = parent::isValid($data);
     // Custom valid
     if ($valid) {
         // Check auth
         try {
             $testService = new Zend_Service_Amazon_S3($data['accessKey'], $data['secretKey'], $data['region']);
             $buckets = $testService->getBuckets();
         } catch (Exception $e) {
             $this->addError('Please double check your access keys.');
             return false;
         }
         // Check bucket
         try {
             if (!in_array($data['bucket'], $buckets)) {
                 if (!$testService->createBucket($data['bucket'], $data['region'])) {
                     throw new Exception('Could not create or find bucket');
                 }
             }
         } catch (Exception $e) {
             $this->addError('Bucket name is already taken and could not be created.');
             return false;
         }
     }
     return $valid;
 }
开发者ID:febryantosulistyo,项目名称:ClassicSocial,代码行数:27,代码来源:S3.php

示例2: gc

 public function gc()
 {
     $config = self::$_registry->get("config");
     $s3config = $config['services']['S3'];
     $s3 = new Zend_Service_Amazon_S3($s3config['key'], $s3config['secret']);
     $select = $this->_dbTable->select();
     $select->order("timestamp ASC")->limit(50);
     $delShares = $this->_dbAdapter->fetchAll($select);
     $deletedShares = array();
     foreach ($delShares as $delShare) {
         $objectKey = $delShare['alias'] . "/" . $delShare['share'] . "-" . $delShare['download_secret'] . "/" . $delShare['filename'];
         $object = $s3config['sharesBucket'] . "/" . $objectKey;
         if ($s3->removeObject($object)) {
             $deletedShares[] = $delShare['id'];
         }
     }
     if (!empty($deletedShares)) {
         $querystring = "DELETE from " . $this->_dbAdapter->quoteTableAs($this->_dbTable->getTableName()) . " WHERE ";
         do {
             $line = $this->_dbAdapter->quoteInto("id = ?", current($deletedShares));
             $querystring .= $line;
             next($deletedShares);
             if (current($deletedShares)) {
                 $querystring .= " OR ";
             }
         } while (current($deletedShares));
         $this->_dbAdapter->query($querystring);
     }
     $removedNum = count($deletedShares);
     return $removedNum;
 }
开发者ID:henvic,项目名称:MediaLab,代码行数:31,代码来源:RemoveFiles.php

示例3: _sendS3

 private function _sendS3($tmpfile, $name)
 {
     $config = new Zend_Config_Ini('../application/configs/amazon.ini', 's3');
     $s3 = new Zend_Service_Amazon_S3($config->access_key, $config->secret_key);
     $bytes = file_get_contents($tmpfile);
     return $s3->putObject($config->imagebucket . "/" . $name . ".jpg", $bytes, array(Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ));
 }
开发者ID:austinphp,项目名称:AustinPHP,代码行数:7,代码来源:IndexController.php

示例4: syncDirectory

 public function syncDirectory()
 {
     $accessKey = Mage::getStoreConfig('amazonsync/general/access_key_id');
     $secretKey = Mage::getStoreConfig('amazonsync/general/secret_access_key');
     $bucket = Mage::getStoreConfig('amazonsync/general/s3_bucket_path');
     $prefix = Mage::getStoreConfig('amazonsync/general/prefix');
     $magentoDir = Mage::getStoreConfig('amazonsync/general/magento_directory');
     $magentoDir = Mage::getBaseDir() . "/" . $magentoDir;
     //Return if S3 settings are empty
     if (!($accessKey && $secretKey && $bucket)) {
         return;
     }
     //Prepare meta data for uploading. All uploaded images are public
     $meta = array(Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ);
     $s3 = new Zend_Service_Amazon_S3($accessKey, $secretKey);
     //Build prefix for all files on S3
     if ($prefix) {
         $cdnPrefix = $bucket . '/' . $prefix;
     } else {
         $cdnPrefix = $bucket;
     }
     $allFiles = array();
     if (is_dir($magentoDir)) {
         $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($magentoDir), RecursiveIteratorIterator::SELF_FIRST);
         $dir = null;
         foreach ($objects as $name => $object) {
             //Get name of the file and create its key on S3
             if (!($object->getFileName() == '.' || $object->getFileName() == '..')) {
                 if (is_dir($object)) {
                     continue;
                 }
                 $fileName = str_replace($magentoDir, '', $name);
                 $cdnPath = $cdnPrefix . $fileName;
                 //Full path to uploaded file
                 $file = $name;
                 //Upload original file
                 $allFiles[] = $cdnPath;
                 if (!$s3->putFile($file, $cdnPath, $meta)) {
                     $msg = 'Can\'t upload original image (' . $file . ') to S3 with ' . $cdnPath . ' key';
                     throw new Mage_Core_Exception($msg);
                 }
             }
         }
         //Remove Not Matched Files
         foreach ($s3->getObjectsByBucket($bucket) as $object) {
             $object = $bucket . '/' . $object;
             if (!in_array($object, $allFiles)) {
                 $s3->removeObject($object);
             }
         }
         return 'All files uploaded to S3 with ' . $bucket . ' bucket';
     } else {
         $msg = $magentoDir . ' directory does not exist';
         throw new Mage_Core_Exception($msg);
     }
 }
开发者ID:brentwpeterson,项目名称:magento-amazon-s3-sync,代码行数:56,代码来源:Syncfile.php

示例5: setUp

 /**
  * Sets up this test case
  *
  * @return void
  */
 public function setUp()
 {
     Zend_Service_Amazon_S3::setKeys(constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'), constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEYID'));
     if (!stream_wrapper_register('s3', 'Zend_Service_Amazon_S3')) {
         $this->fail('Unable to register s3:// streams wrapper');
     }
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:12,代码来源:OnlineTest.php

示例6: fetchMetadata

 /**
  * Get a key/value array of metadata for the given path.
  *
  * @param  string $path
  * @param  array $options
  * @return array
  */
 public function fetchMetadata($path, $options = array())
 {
     try {
         return $this->_s3->getInfo($this->_getFullPath($path, $options));
     } catch (Zend_Service_Amazon_S3_Exception $e) {
         throw new Zend_Cloud_StorageService_Exception('Error on fetch: ' . $e->getMessage(), $e->getCode(), $e);
     }
 }
开发者ID:laiello,项目名称:vinhloi,代码行数:15,代码来源:S3.php

示例7: indexAction

 public function indexAction()
 {
     $s3 = new Zend_Service_Amazon_S3('AKIAJ5HTOSBB7ITPA6VQ', 'n8ZjV8xz/k/FxBGhrVduYlSXVFFmep7aZJ/NOsoj');
     $this->view->buckets = $s3->getBuckets();
     $bucketName = 'vaultman';
     $ret = $s3->getObjectsByBucket($bucketName);
     $this->view->objects = $ret;
     $this->view->form = new Mybase_Form_Files();
     $formData = $this->getRequest()->getPost();
     if ($this->_request->isPost()) {
         $s3->registerStreamWrapper("s3");
         //file_put_contents("s3://".$bucketName."/".$_FILES['img']['name'], fopen($_FILES['img']['tmp_name'], 'r'));
         $adapter = new Zend_File_Transfer_Adapter_Http();
         $adapter->setDestination("s3://" . $bucketName . "/");
         //$adapter->receive();
     }
 }
开发者ID:besters,项目名称:My-Base,代码行数:17,代码来源:FilesController.php

示例8: s3_put_file

function s3_put_file($access_key_id, $secret_access_key, $bucket_path, $file_path, $mime)
{
    $result = FALSE;
    if ($access_key_id && $secret_access_key && $bucket_path && $file_path) {
        try {
            $s3 = new Zend_Service_Amazon_S3($access_key_id, $secret_access_key);
            $meta = array();
            $meta[Zend_Service_Amazon_S3::S3_ACL_HEADER] = Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ;
            if ($mime) {
                $meta[Zend_Service_Amazon_S3::S3_CONTENT_TYPE_HEADER] = $mime;
            }
            if ($s3->putFileStream($file_path, $bucket_path, $meta)) {
                $result = TRUE;
            }
        } catch (Exception $ex) {
            //print $ex->getMessage();
        }
    }
    return $result;
}
开发者ID:ronniebrito,项目名称:moodle_moviemasher,代码行数:20,代码来源:s3utils.php

示例9: setAvatar

 public function setAvatar($userInfo, $source)
 {
     $registry = Zend_Registry::getInstance();
     $config = $registry->get("config");
     $people = Ml_Model_People::getInstance();
     $s3config = $config['services']['S3'];
     $s3 = new Zend_Service_Amazon_S3($s3config['key'], $s3config['secret']);
     try {
         $im = new Imagick($source);
         $im->setimagecompressionquality(self::$_imageQuality);
         $dim = $im->getimagegeometry();
         if (!$dim) {
             return false;
         }
     } catch (Exception $e) {
         return false;
     }
     $sizesInfo = array();
     $tmpFilenames = array();
     $im->unsharpMaskImage(0, 0.5, 1, 0.05);
     foreach ($this->_sizes as $sizeInfo) {
         $tmpFilenames[$sizeInfo[1]] = tempnam(sys_get_temp_dir(), 'HEADSHOT');
         if ($sizeInfo[0] == "sq") {
             if ($dim['height'] < $dim['width']) {
                 $size = $dim['height'];
             } else {
                 $size = $dim['width'];
             }
             //@todo let the user crop using Javascript, so he/she can set the offsets (default 0,0)
             $im->cropThumbnailImage($sizeInfo[3], $sizeInfo[3]);
         } else {
             if ($dim['width'] < $sizeInfo[3] && $dim['height'] < $sizeInfo[3] && $sizeInfo[2] != 'huge') {
                 copy($source, $tmpFilenames[$sizeInfo[1]]);
             } else {
                 if ($dim['width'] > $dim['height']) {
                     $im->resizeimage($sizeInfo[3], 0, Imagick::FILTER_LANCZOS, 1);
                 } else {
                     $im->resize(0, $sizeInfo[3], Imagick::FILTER_LANCZOS, 1);
                 }
             }
         }
         $im->writeimage($tmpFilenames[$sizeInfo[1]]);
         $imGeometry = $im->getimagegeometry();
         $sizesInfo[$sizeInfo[0]] = array("w" => $imGeometry['width'], "h" => $imGeometry['height']);
     }
     $oldData = unserialize($userInfo['avatarInfo']);
     //get the max value of mt_getrandmax() or the max value of the unsigned int type
     if (mt_getrandmax() < 4294967295.0) {
         $maxRand = mt_getrandmax();
     } else {
         $maxRand = 4294967295.0;
     }
     $newSecret = mt_rand(0, $maxRand);
     if (isset($oldData['secret'])) {
         while ($oldData['secret'] == $newSecret) {
             $newSecret = mt_rand(0, $maxRand);
         }
     }
     foreach ($tmpFilenames as $size => $file) {
         if ($size == '_h') {
             $privacy = Zend_Service_Amazon_S3::S3_ACL_PRIVATE;
         } else {
             $privacy = Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ;
         }
         $picAddr = $s3config['headshotsBucket'] . "/" . $userInfo['id'] . '-' . $newSecret . $size . '.jpg';
         $meta = array(Zend_Service_Amazon_S3::S3_ACL_HEADER => $privacy, "Content-Type" => Zend_Service_Amazon_S3::getMimeType($picAddr), "Cache-Control" => "max-age=37580000, public", "Expires" => "Thu, 10 May 2029 00:00:00 GMT");
         $s3->putFile($file, $picAddr, $meta);
         unlink($file);
     }
     $newAvatarInfo = serialize(array("sizes" => $sizesInfo, "secret" => $newSecret));
     $people->update($userInfo['id'], array("avatarInfo" => $newAvatarInfo));
     //delete the old files
     $this->deleteFiles($userInfo);
     return true;
 }
开发者ID:henvic,项目名称:MediaLab,代码行数:75,代码来源:Picture.php

示例10: tearDown

 /**
  * Tears down this test case
  *
  * @return void
  */
 public function tearDown()
 {
     if (!$this->_config) {
         return;
     }
     // Delete the bucket here
     $s3 = new Zend_Service_Amazon_S3($this->_config->get(Zend_Cloud_StorageService_Adapter_S3::AWS_ACCESS_KEY), $this->_config->get(Zend_Cloud_StorageService_Adapter_S3::AWS_SECRET_KEY));
     $s3->removeBucket($this->_config->get(Zend_Cloud_StorageService_Adapter_S3::BUCKET_NAME));
     parent::tearDown();
 }
开发者ID:jsnshrmn,项目名称:Suma,代码行数:15,代码来源:S3Test.php

示例11: tearDown

 public function tearDown()
 {
     unset($this->_amazon->debug);
     $this->_amazon->cleanBucket($this->_bucket);
     $this->_amazon->removeBucket($this->_bucket);
     sleep(1);
 }
开发者ID:jsnshrmn,项目名称:Suma,代码行数:7,代码来源:OnlineTest.php

示例12: stream_stat

 /**
  * Returns data array of stream variables
  *
  * @return array
  */
 public function stream_stat()
 {
     if (!$this->_objectName) {
         return false;
     }
     $stat = array();
     $stat['dev'] = 0;
     $stat['ino'] = 0;
     $stat['mode'] = 0;
     $stat['nlink'] = 0;
     $stat['uid'] = 0;
     $stat['gid'] = 0;
     $stat['rdev'] = 0;
     $stat['size'] = 0;
     $stat['atime'] = 0;
     $stat['mtime'] = 0;
     $stat['ctime'] = 0;
     $stat['blksize'] = 0;
     $stat['blocks'] = 0;
     $info = $this->_s3->getInfo($this->_objectName);
     if (!empty($info)) {
         $stat['size'] = $info['size'];
         $stat['atime'] = time();
         $stat['mtime'] = $info['mtime'];
     }
     return $stat;
 }
开发者ID:AholibamaSI,项目名称:plymouth-webapp,代码行数:32,代码来源:Stream.php

示例13: stream_stat

 /**
  * Returns data array of stream variables
  *
  * @return array
  */
 public function stream_stat()
 {
     if (!$this->_objectName) {
         return false;
     }
     $stat = array();
     $stat['dev'] = 0;
     $stat['ino'] = 0;
     $stat['mode'] = 0777;
     $stat['nlink'] = 0;
     $stat['uid'] = 0;
     $stat['gid'] = 0;
     $stat['rdev'] = 0;
     $stat['size'] = 0;
     $stat['atime'] = 0;
     $stat['mtime'] = 0;
     $stat['ctime'] = 0;
     $stat['blksize'] = 0;
     $stat['blocks'] = 0;
     if (($slash = strchr($this->_objectName, '/')) === false || $slash == strlen($this->_objectName) - 1) {
         /* bucket */
         $stat['mode'] |= 040000;
     } else {
         $stat['mode'] |= 0100000;
     }
     $info = $this->_s3->getInfo($this->_objectName);
     if (!empty($info)) {
         $stat['size'] = $info['size'];
         $stat['atime'] = time();
         $stat['mtime'] = $info['mtime'];
     }
     return $stat;
 }
开发者ID:fredcido,项目名称:simuweb,代码行数:38,代码来源:Stream.php

示例14: _makeRequest

 /**
  *
  * @param <type> $method
  * @param <type> $path
  * @param <type> $params
  * @param <type> $headers
  * @param <type> $data
  * @return <type> 
  */
 public function _makeRequest($method, $path = '', $params = null, $headers = array(), $data = null)
 {
     if ('PUT' == $method && $this->defaultAcl) {
         $headers = array_merge(array(self::S3_ACL_HEADER => $this->defaultAcl), $headers);
     }
     return parent::_makeRequest($method, $path, $params, $headers, $data);
 }
开发者ID:JoshuaEstes,项目名称:sfAmazonS3Plugin,代码行数:16,代码来源:sfAmazonS3.class.php

示例15: tearDown

 public function tearDown()
 {
     if (!constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED')) {
         return;
     }
     unset($this->_amazon->debug);
     $this->_amazon->cleanBucket($this->_bucket);
     $this->_amazon->removeBucket($this->_bucket);
 }
开发者ID:navassouza,项目名称:zf2,代码行数:9,代码来源:OnlineTest.php


注:本文中的Zend_Service_Amazon_S3类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。