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


PHP S3::putObject方法代码示例

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


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

示例1: UploadToCloud

 function UploadToCloud($file_source, $model_id, $model_name, $type, $mime_type, $file_ext = null)
 {
     App::import('Vendor', 'S3', array('file' => 'S3.php'));
     $s3 = new S3($this->awsAccessKey, $this->awsSecretKey, true, "s3-ap-southeast-1.amazonaws.com");
     $input = $s3->inputFile($file_source, false);
     $ext = pathinfo($file_source, PATHINFO_EXTENSION);
     if ($file_ext != null) {
         $obj = $s3->putObject($input, $this->bucketName, "contents/" . $model_name . "/" . $model_id . "/" . $model_id . "_" . $type . "." . $file_ext, S3::ACL_PUBLIC_READ, array(), array("Content-Type" => $mime_type));
     } else {
         $obj = $s3->putObject($input, $this->bucketName, "contents/" . $model_name . "/" . $model_id . "/" . $model_id . "_" . $type . "." . $ext, S3::ACL_PUBLIC_READ, array(), array("Content-Type" => $mime_type));
     }
     return $obj;
 }
开发者ID:koprals,项目名称:coda-gosales-hsbc,代码行数:13,代码来源:GeneralComponent.php

示例2: write

 /**
  * Write 
  * 
  * @param string $path        Short path
  * @param string $data        Data
  * @param array  $httpHeaders HTTP headers OPTIONAL
  *  
  * @return boolean
  */
 public function write($path, $data, array $httpHeaders = array())
 {
     $result = false;
     try {
         $result = $this->client->putObject($data, \XLite\Core\Config::getInstance()->CDev->AmazonS3Images->bucket, $path, \S3::ACL_PUBLIC_READ, array(), $httpHeaders);
         $result = (bool) $result;
         $message = true;
     } catch (\S3Exception $e) {
         $result = false;
         \XLite\Logger::getInstance()->registerException($e);
     }
     return $result;
 }
开发者ID:kingsj,项目名称:core,代码行数:22,代码来源:S3.php

示例3: upload_image

 public function upload_image()
 {
     $config = array('allowed_types' => 'jpg|jpeg|gif|png', 'upload_path' => './temp', 'max_size' => 3072, 'overwrite' => true);
     $this->load->library('upload', $config);
     $this->upload->overwrite = true;
     $response['responseStatus'] = "Not OK";
     if (!$this->upload->do_upload()) {
         $response['responseStatus'] = "Your image could not be uploaded";
     } else {
         $data = $this->upload->data();
         //instantiate the class
         $s3 = new S3(awsAccessKey, awsSecretKey);
         $ext = pathinfo($data['full_path'], PATHINFO_EXTENSION);
         $imgName = (string) time() . "." . $ext;
         $input = S3::inputFile($data['full_path'], FALSE);
         if ($s3->putObject(file_get_contents($data['full_path']), "tlahui-content", $imgName, S3::ACL_PUBLIC_READ)) {
             $response['responseStatus'] = "OK";
             $response['url'] = "https://s3.amazonaws.com/tlahui-content/" . $imgName;
             unlink($data['full_path']);
         } else {
             $response['responseStatus'] = "Your image could not be uploaded";
             unlink($data['full_path']);
         }
     }
     echo json_encode($response);
 }
开发者ID:mvalenciarmz,项目名称:PagosElectronicos-Upload,代码行数:26,代码来源:upload.php

示例4: createSquareFile

 static function createSquareFile($filename, $readPath, $writePath, $writeSize = 300, $upload = true)
 {
     # make sure all inputs are clean
     if (!self::areClean(array($filename, $readPath, $writePath, $writeSize))) {
         return false;
     }
     if (!self::imageMagickInstalled()) {
         return false;
     }
     if (!($size = getimagesize($readPath))) {
         return false;
     }
     $savePath = sfConfig::get('sf_image_dir') . DIRECTORY_SEPARATOR . $writePath . DIRECTORY_SEPARATOR . $filename;
     if ($size[0] > $size[1] * 2 || $size[1] > $size[0] * 2) {
         # pad to square if one dimension is more than twice the other dimension
         exec(sfConfig::get('app_imagemagick_binary_path') . " {$readPath} -virtual-pixel background -background white -set option:distort:viewport \"%[fx:max(w,h)]x%[fx:max(w,h)]-%[fx:max((h-w)/2,0)]-%[fx:max((w-h)/2,0)]\" -filter point -distort SRT 0 +repage {$savePath}");
     } else {
         # otherwise, crop to square
         exec(sfConfig::get('app_imagemagick_binary_path') . " {$readPath} -virtual-pixel edge -set option:distort:viewport \"%[fx:min(w,h)]x%[fx:min(w,h)]+%[fx:max((w-h)/2,0)]+%[fx:max((h-w)/2,0)]\" -filter point -distort SRT 0 +repage {$savePath}");
     }
     # resize
     exec(sfConfig::get('app_imagemagick_binary_path') . " {$savePath} -resize {$writeSize}x{$writeSize} {$savePath}");
     # if s3 enabled, save to s3
     if ($upload && sfConfig::get('app_amazon_enable_s3')) {
         $s3 = new S3(sfConfig::get('app_amazon_access_key'), sfConfig::get('app_amazon_secret_key'));
         $input = $s3->inputResource($f = fopen($savePath, "rb"), $s = filesize($savePath));
         $uri = self::generateS3path($writePath, $filename);
         if (!S3::putObject($input, sfConfig::get('app_amazon_s3_bucket'), $uri, S3::ACL_PUBLIC_READ)) {
             return false;
         }
     }
     return $savePath;
 }
开发者ID:silky,项目名称:littlesis,代码行数:33,代码来源:ImageTable.class.php

示例5: storecontenttofile

function storecontenttofile($content, $key, $sec = "private")
{
    if ($GLOBALS['filehandertype'] == 's3') {
        if ($sec == "public" || $sec == "public-read") {
            $sec = "public-read";
        } else {
            $sec = "private";
        }
        $s3 = new S3($GLOBALS['AWSkey'], $GLOBALS['AWSsecret']);
        if ($s3->putObject($content, $GLOBALS['AWSbucket'], $key, $sec)) {
            return true;
        } else {
            return false;
        }
    } else {
        $base = rtrim(dirname(dirname(__FILE__)), '/\\') . '/filestore/';
        $dir = $base . dirname($key);
        $fn = basename($key);
        if (!is_dir($dir)) {
            mkdir_recursive($dir);
        }
        $fh = @fopen($dir . '/' . $fn, 'wb');
        if ($fh) {
            fwrite($fh, $content);
            fclose($fh);
            return true;
        } else {
            return false;
        }
    }
}
开发者ID:ericvanboven,项目名称:IMathAS,代码行数:31,代码来源:filehandler.php

示例6: moveFileToS3

 /**
  * Загружает файл в S3.
  */
 public static function moveFileToS3($fileName, $mimeType = null, $baseName = null)
 {
     self::checkEnv($ctx = Context::last());
     $conf = $ctx->config->get('modules/s3');
     $s3 = new S3($conf['accesskey'], $conf['secretkey']);
     if (!($bucketName = trim($ctx->config->get('modules/s3/bucket', 'files'), '/'))) {
         throw new RuntimeException(t('Модуль s3 не настроен (bucket).'));
     }
     if ($folderName = $ctx->config->get('module/s3/folder', 'files')) {
         $folderName .= '/';
     }
     /*
     if (!in_array($bucketName, $s3->listBuckets()))
       throw new RuntimeException(t('Нет такой папки: ' . $bucketName));
     */
     if ($f = fopen($fileName, 'rb')) {
         if (null === $baseName) {
             $baseName = basename($fileName);
         }
         if (!($r = S3::inputResource($f, filesize($fileName)))) {
             throw new RuntimeException(t('Не удалось создать ресурс из файла %filename.', array('%filename' => $fileName)));
         }
         if (!($response = S3::putObject($r, $bucketName, $folderName . $baseName, S3::ACL_PUBLIC_READ))) {
             throw new RuntimeException(t('Не удалось загрузить файл %filename в папку %bucket.', array('%filename' => $fileName, '%bucket' => $bucketName)));
         }
         $url = 'http://' . $bucketName . '.s3.amazonaws.com/' . $folderName . $baseName;
         Logger::log('S3: ' . $url);
         return $url;
     }
 }
开发者ID:umonkey,项目名称:molinos-cms,代码行数:33,代码来源:class.s3api.php

示例7: create

 function create($localpath, $remotepath)
 {
     $localpath = realpath($localpath);
     if (S3::putObject(S3::inputFile($localpath), $this->backupBucket, $remotepath, S3::ACL_PRIVATE)) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
开发者ID:pcisneros,项目名称:glab-ci-ext,代码行数:9,代码来源:S3_Backup.php

示例8: save_sized_image

 function save_sized_image($original, $key, $size, $folder)
 {
     $file = $folder . "/" . $key . ".jpg";
     $file_path = IMAGES_DIR . "/" . $file;
     resize_image($original, $size, $file_path);
     if (STORAGE_STRATEGY == 's3') {
         $input = S3::inputFile($file_path);
         S3::putObject($input, S3_BUCKET, $file, S3::ACL_PUBLIC_READ);
     }
 }
开发者ID:schlos,项目名称:electionleaflets,代码行数:10,代码来源:image_que.php

示例9: action_create

 /**
  * CRUD controller: CREATE
  */
 public function action_create()
 {
     $this->auto_render = FALSE;
     $this->template = View::factory('js');
     if (!isset($_FILES['image'])) {
         $this->template->content = json_encode('KO');
         return;
     }
     $image = $_FILES['image'];
     if (core::config('image.aws_s3_active')) {
         require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php');
         $s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key'));
     }
     if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, explode(',', core::config('image.allowed_formats'))) or !Upload::size($image, core::config('image.max_image_size') . 'M')) {
         if (Upload::not_empty($image) and !Upload::type($image, explode(',', core::config('image.allowed_formats')))) {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not valid format, please use one of this formats "%s"'), core::config('image.allowed_formats'))));
             return;
         }
         if (!Upload::size($image, core::config('image.max_image_size') . 'M')) {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not of valid size. Size is limited to %s MB per image'), core::config('image.max_image_size'))));
             return;
         }
         $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
         return;
     } elseif ($image != NULL) {
         // saving/uploading img file to dir.
         $path = 'images/cms/';
         $root = DOCROOT . $path;
         //root folder
         $image_name = URL::title(pathinfo($image['name'], PATHINFO_FILENAME));
         $image_name = Text::limit_chars(URL::title(pathinfo($image['name'], PATHINFO_FILENAME)), 200);
         $image_name = time() . '.' . $image_name;
         // if folder does not exist, try to make it
         if (!file_exists($root) and !@mkdir($root, 0775, true)) {
             // mkdir not successful ?
             $this->template->content = json_encode(array('msg' => __('Image folder is missing and cannot be created with mkdir. Please correct to be able to upload images.')));
             return;
             // exit function
         }
         // save file to root folder, file, name, dir
         if ($file = Upload::save($image, $image_name, $root)) {
             // put image to Amazon S3
             if (core::config('image.aws_s3_active')) {
                 $s3->putObject($s3->inputFile($file), core::config('image.aws_s3_bucket'), $path . $image_name, S3::ACL_PUBLIC_READ);
             }
             $this->template->content = json_encode(array('link' => Core::config('general.base_url') . $path . $image_name));
             return;
         } else {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image file could not been saved.')));
             return;
         }
         $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
     }
 }
开发者ID:JeffPedro,项目名称:project-garage-sale,代码行数:57,代码来源:cmsimages.php

示例10: putObject

 /**
  * Put an object into an S3 bucket.
  *
  * @param $filePath
  * @param $bucket
  * @param $uriPath
  * @param $permissions
  *
  * @return bool
  */
 protected function putObject($filePath, $bucket, $uriPath, $permissions)
 {
     $object = empty($filePath) ? '' : array('file' => $filePath);
     $headers = array();
     if (!empty($object) && !empty($this->getSettings()->expires) && DateTimeHelper::isValidIntervalString($this->getSettings()->expires)) {
         $expires = new DateTime();
         $now = new DateTime();
         $expires->modify('+' . $this->getSettings()->expires);
         $diff = $expires->format('U') - $now->format('U');
         $headers['Cache-Control'] = 'max-age=' . $diff . ', must-revalidate';
     }
     return $this->_s3->putObject($object, $bucket, $uriPath, $permissions, array(), $headers);
 }
开发者ID:webremote,项目名称:craft_boilerplate,代码行数:23,代码来源:S3AssetSourceType.php

示例11: gsUpload

function gsUpload($file, $bucket, $remoteFile)
{
    $ret = false;
    $key = 'GOOGT4X7CFTWS2VWN2HT';
    $secret = 'SEWZTyKZH6dNbjbT2CHg5Q5pUh5Y5+iinj0yBFB4';
    $server = 'storage.googleapis.com';
    $s3 = new S3($key, $secret, false, $server);
    $metaHeaders = array();
    $requestHeaders = array();
    if ($s3->putObject($s3->inputFile($file, false), $bucket, $remoteFile, S3::ACL_PUBLIC_READ, $metaHeaders, $requestHeaders)) {
        $ret = true;
    }
    return $ret;
}
开发者ID:risyasin,项目名称:webpagetest,代码行数:14,代码来源:gstest.php

示例12: uploadFile

 function uploadFile($type, $filename, $check_first = true, $debug = false)
 {
     $localPath = sfConfig::get('sf_image_dir') . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $filename;
     $input = $this->s3->inputResource($f = fopen($localPath, "rb"), filesize($s = $localPath));
     $uri = ImageTable::generateS3path($type, $filename);
     if ($check_first && $this->s3->getObjectInfo(sfConfig::get('app_amazon_s3_bucket'), $uri) !== false) {
         return;
     }
     if (S3::putObject($input, sfConfig::get('app_amazon_s3_bucket'), $uri, S3::ACL_PUBLIC_READ)) {
         print "UPLOADED: " . $uri . "\n";
     } else {
         if ($debug) {
             print "Couldn't upload image to S3: " . $uri . "\n";
         }
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:16,代码来源:UploadS3ImagesTask.class.php

示例13: uploadTmpFile

 function uploadTmpFile($source, $overwrite = false, $debug = false, $localdir = false)
 {
     $filePath = $this->getTmpPath($source, $localdir);
     $size = filesize($filePath);
     $input = $this->s3->inputResource($f = fopen($filePath, "r"), $size);
     $url = ReferenceTable::generateS3path($source);
     if (!$overwrite && $this->s3->getObjectInfo(sfConfig::get('app_amazon_s3_bucket'), $url) !== false) {
         print "ALREADY UPLOADED: " . $url . "\n";
         return;
     }
     if (S3::putObject($input, sfConfig::get('app_amazon_s3_bucket'), $url, S3::ACL_PUBLIC_READ)) {
         print "UPLOADED: " . $url . "\n";
     } else {
         if ($debug) {
             print "Couldn't upload reference to S3: " . $url . "\n";
         }
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:18,代码来源:UploadS3ReferencesTask.class.php

示例14: putFile

 function putFile($filename)
 {
     $s3svc = new S3();
     // Removing the first slash is important - otherwise the URL is different.
     $aws_filename = eregi_replace('^/', '', $filename);
     $filename = $_SERVER['DOCUMENT_ROOT'] . $filename;
     $mime_type = NFilesystem::getMimeType($filename);
     // Read the file into memory.
     $fh = fopen($filename, 'rb');
     $contents = fread($fh, filesize($filename));
     fclose($fh);
     $s3svc->putBucket(MIRROR_S3_BUCKET);
     $out = $s3svc->putObject($aws_filename, $contents, MIRROR_S3_BUCKET, 'public-read', $mime_type);
     // Now the file is accessable at:
     //		http://MIRROR_S3_BUCKET.s3.amazonaws.com/put/the/filename/here.jpg 	OR
     // 		http://s3.amazonaws.com/MIRROR_S3_BUCKET/put/the/filename/here.jpg
     unset($s3svc);
 }
开发者ID:nonfiction,项目名称:nterchange,代码行数:18,代码来源:s3_mirror.php

示例15: persist

 function persist($prefix, $name, $sBlobData, $headers = array())
 {
     //create a unique name for s3 store
     $storeName = \com\indigloo\media\FileStore::getHashedName($name);
     $storeName = $prefix . $storeName;
     $bucket = Config::getInstance()->get_value("aws.bucket");
     $awsKey = Config::getInstance()->get_value("aws.key");
     $awsSecret = Config::getInstance()->get_value("aws.secret");
     if (Config::getInstance()->is_debug()) {
         Logger::getInstance()->debug(" s3 bucket is => {$bucket}");
         Logger::getInstance()->debug(" original name => {$name}");
         Logger::getInstance()->debug(" file path is => {$storeName} ");
     }
     $s3 = new \S3($awsKey, $awsSecret, false);
     $metaHeaders = array();
     //$input, $bucket, $uri, $acl , $metaHeaders, $requestHeaders
     $s3->putObject($sBlobData, $bucket, $storeName, \S3::ACL_PUBLIC_READ, $metaHeaders, $headers);
     return $storeName;
 }
开发者ID:rjha,项目名称:webgloo,代码行数:19,代码来源:S3Store.php


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