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


PHP AmazonS3::batch方法代码示例

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


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

示例1: upload

 /**
  * Upload an array of files to S3
  *
  * @param $files The PHP $_FILES array which references the files to upload
  * @param string $target The relative path in the S3 bucket to upload to
  * @param array $options An array of options to pass to the S3 upload client
  * @return array|bool If ok, will return an array of URLs for the uploaded items
  */
 public function upload($files, $target = '', array $options = array())
 {
     if (!is_array($files) || !empty($files['tmp_name'])) {
         $files = array($files);
     }
     $options = array_merge(array('acl' => AmazonS3::ACL_PUBLIC), $options);
     $individualFiles = array();
     foreach ($files as $k => $file) {
         if (is_array($file)) {
             $filename = basename($file['name']);
             $file = $file['tmp_name'];
         } else {
             $filename = basename($file);
         }
         $individualFiles[] = $filename;
         $options['fileUpload'] = $file;
         $this->s3->batch()->create_object($this->bucket, $target . $filename, $options);
     }
     $response = $this->s3->batch()->send();
     if ($response->areOK()) {
         $data = array();
         foreach ($individualFiles as $filename) {
             $data[] = $this->s3->get_object_url($this->bucket, $target . $filename);
         }
         return $data;
     }
     return false;
 }
开发者ID:ChrstnMgcn,项目名称:revolution,代码行数:36,代码来源:modaws.class.php

示例2: syncToS3

 protected function syncToS3($arguments = array(), $options = array())
 {
     list($bucket, $prefix) = explode(':', $arguments['destination']);
     $file_list = sfFinder::type('file')->in($arguments['source']);
     $object_list_response = $this->s3->list_objects($bucket);
     if (!$object_list_response->isOk()) {
         throw new sfException($object_list_response->body->Message);
     }
     if (isset($object_list_response->body->Contents)) {
         foreach ($object_list_response->body->Contents as $object) {
             // var_dump($object->LastModified);
             $object_list[] = $object->Key;
         }
     }
     $files_queued = 0;
     foreach ($file_list as $file) {
         $filename = explode(DIRECTORY_SEPARATOR, $file);
         $filename = array_pop($filename);
         $offset = strpos($file, $arguments['source']);
         $s3_location = substr(str_replace($arguments['source'], '', substr($file, $offset)), 1);
         if (in_array($s3_location, $object_list)) {
             continue;
         }
         $this->s3->batch()->create_object($bucket, $s3_location, array('fileUpload' => $file));
         $files_queued++;
         $this->logSection('file+', $bucket . ':' . $s3_location);
     }
     if ($files_queued <= 0) {
         $this->log('All files have already been synced, no need to upload any files');
         return;
     }
     $upload_response = $this->s3->batch()->send();
     if (!$upload_response->areOk()) {
         throw new sfException($upload_response->body->Message);
     }
     $this->log('Files synced to bucket');
 }
开发者ID:JoshuaEstes,项目名称:sfAmazonPlugin,代码行数:37,代码来源:s3SyncTask.class.php

示例3: array

 	defined below. This assumes that you have a directory called "test_files"
 	that actually contains some files you want to upload.
 */
 $list_of_files = filter_file_list(glob('./test_files/*'));
 // Prepare to hold the individual filenames
 $individual_filenames = array();
 // Loop over the list, referring to a single file at a time
 foreach ($list_of_files as $file) {
     // Grab only the filename part of the path
     $filename = explode(DIRECTORY_SEPARATOR, $file);
     $filename = array_pop($filename);
     // Store the filename for later use
     $individual_filenames[] = $filename;
     /* Prepare to upload the file to our new S3 bucket. Add this
        request to a queue that we won't execute quite yet. */
     $s3->batch()->create_object($bucket, $filename, array('fileUpload' => $file));
 }
 /* Execute our queue of batched requests. This may take a few seconds to a
    few minutes depending on the size of the files and how fast your upload
    speeds are. */
 $file_upload_response = $s3->batch()->send();
 /* Since a batch of requests will return multiple responses, let's
    make sure they ALL came back successfully using `areOK()` (singular
    responses use `isOK()`). */
 if ($file_upload_response->areOK()) {
     // Loop through the individual filenames
     foreach ($individual_filenames as $filename) {
         /* Display a URL for each of the files we uploaded. Since uploads default to
            private (you can choose to override this setting when uploading), we'll
            pre-authenticate the file URL for the next 5 minutes. */
         echo $s3->get_object_url($bucket, $filename, '5 minutes') . PHP_EOL . PHP_EOL;
开发者ID:anil-kodali,项目名称:aws-sdk-for-php,代码行数:31,代码来源:cli-s3_get_urls_for_uploads.php


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