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


PHP S3类代码示例

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


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

示例1: upload

 function upload()
 {
     $error = "test";
     if (isset($_POST['submitbtn'])) {
         if (array_key_exists('userFile', $_FILES)) {
             if ($_FILES['userFile']['error'] === UPLOAD_ERR_OK) {
                 $filename = $_FILES["userFile"]["name"];
                 $ext = pathinfo($filename, PATHINFO_EXTENSION);
                 $allowed = array("doc", "docx", "rtf", "pdf", "txt", "odf");
                 $fname = $_FILES["userFile"]["tmp_name"];
                 // Make sure extension matches
                 if (in_array($ext, $allowed)) {
                     if ($_FILES['userFile']['size'] < 2097152) {
                         $bucket = 'sublite-resumes';
                         //Can use existing configs when merging with sublite
                         $s3 = new S3("AKIAI7IVRJCSAWFTTS7Q", "B0qzRQJ1KlLy+STC2BspwT9oZONjt+U6sRNqaRr5");
                         $s3->putBucket($bucket, S3::ACL_PUBLIC_READ);
                         $actual_image_name = time() . '.' . $ext;
                         if ($s3->putObjectFile($fname, $bucket, $actual_image_name, S3::ACL_PUBLIC_READ)) {
                             $image = 'http://' . $bucket . '.s3.amazonaws.com/' . $actual_image_name;
                             return $image;
                         } else {
                             return "An unknown error occurred during upload!";
                         }
                         /*								// File validated; Upload the file! !!!Need to upload to S3!!!
                         								$uploaddir = 'resumes/';
                         								$uploadfile = basename($_FILES['userFile']['name']);
                         
                         								if (move_uploaded_file($_FILES['userFile']['tmp_name'], $uploaddir.$uploadfile)) {
                         								    return "File is valid, and was successfully uploaded.\n";
                         								} else {
                         								    return "An unknown error occurred during upload!";
                         								} */
                     } else {
                         $error = "Max file size exceeded!";
                     }
                 } else {
                     $error = "Bad file extension!";
                 }
             } else {
                 if ($_FILES['userFile']['error'] === UPLOAD_ERR_FORM_SIZE) {
                     $error = "Max file size exceeded!";
                 } else {
                     if ($_FILES['userFile']['error'] === UPLOAD_ERR_NO_FILE) {
                         $error = "You must choose a file!";
                     } else {
                         $error = "An unknown error occurred during upload!";
                     }
                 }
             }
             return $error;
         }
     }
 }
开发者ID:edwardshe,项目名称:sublite,代码行数:54,代码来源:ResumeUpload.php

示例2: listS3Docs

 private function listS3Docs()
 {
     $s3 = new S3(WH_AWS_WIKIPHOTO_ACCESS_KEY, WH_AWS_WIKIPHOTO_SECRET_KEY);
     $bucket_name = self::AWS_BUCKET;
     $prefix = null;
     $marker = null;
     $maxKeys = null;
     $delimiter = null;
     $returnCommonPrefixes = false;
     $buckets = $s3->getBucket($bucket_name, $prefix, $marker, $maxKeys, $delimiter, $returnCommonPrefixes);
     if (!self::$quiet) {
         print "number of buckets: " . count($buckets) . "\n";
     }
     foreach ($buckets as $path => $details) {
         // match string: doc_folder/doc_file.ending
         if (!preg_match('@^(.*)/(.*)\\.(.*)$@i', $path, $m)) {
             continue;
         }
         list(, $doc_folder, $doc_file, $ending) = $m;
         //validate extension
         if (!in_array($ending, self::$docExts)) {
             continue;
         }
         $prefix = $doc_folder . '/' . $doc_file;
         $files = array($ending);
         list($err, $stageDir) = self::pullFiles($s3, $doc_folder, $doc_file, $ending);
     }
     //now process the display names
     self::processDisplayNames($s3);
 }
开发者ID:ErdemA,项目名称:wikihow,代码行数:30,代码来源:SampleDocProcess.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: listS3Images

 private function listS3Images()
 {
     $s3 = new S3(WH_AWS_WIKIPHOTO_ACCESS_KEY, WH_AWS_WIKIPHOTO_SECRET_KEY);
     $bucket_name = self::AWS_BUCKET;
     $prefix = null;
     $marker = null;
     //$marker = 'paupau/257175/Make Chocolate-1.JPG';
     $maxKeys = 1;
     //$maxKeys = null;
     $delimiter = null;
     $returnCommonPrefixes = false;
     $buckets = $s3->getBucket($bucket_name, $prefix, $marker, $maxKeys, $delimiter, $returnCommonPrefixes);
     print "number of buckets: " . count($buckets) . "\n";
     foreach ($buckets as $path => $details) {
         // match string: username/(1234.zip or 1234/*.jpg)
         if (!preg_match('@^([a-z][-._0-9a-z]{0,30})/([0-9]+)(\\.zip|/.+)$@i', $path, $m)) {
             continue;
         }
         list(, $user, $id, $ending) = $m;
         $id = intval($id);
         if (!$id) {
             continue;
         }
         /*			if (in_array($user, self::$excludeUsers) // don't process anything in excluded people
         				|| preg_match('@^[0-9]+$@', $user)) // don't allow usernames that are all digits
         			{
         				continue;
         			}
         */
         $prefix = $user . '/' . $id;
         $files = array($ending);
         list($err, $stageDir) = self::pullFiles($id, $s3, $prefix, $files);
     }
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:34,代码来源:wikiphotoInfo.php

示例5: 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

示例6: grav_submit_to_s3

function grav_submit_to_s3($entry, $form)
{
    // no file?  no problem.
    if (empty($entry[GFORM_UPLOAD_FIELD_ID])) {
        return;
    }
    $gfs3 = new S3(awsAccessKey, awsSecretKey);
    // url of uploaded file
    $file_url = $entry[GFORM_UPLOAD_FIELD_ID];
    // filename of uploaded file
    $file_name = $_FILES['input_' . GFORM_UPLOAD_FIELD_ID]['name'];
    // ensure bucket is there
    $gfs3->putBucket(BUCKET_NAME, S3::ACL_AUTHENTICATED_READ);
    // clean up filename, split into parts
    $url_parts = parse_url($file_url);
    $full_path = $_SERVER['DOCUMENT_ROOT'] . substr($url_parts['path'], 1);
    if (is_dir($file_name)) {
        $file_name = basename($file_name);
    }
    // this is the full path to the file on S3
    $filename_to_s3 = UPLOAD_PATH . sanitize_file_name($file_name);
    if ($gfs3->putObjectFile($full_path, BUCKET_NAME, $filename_to_s3, S3::ACL_PUBLIC_READ)) {
        return true;
        // upload success
    } else {
        wp_die('It looks like something went wrong while uploading your file. Please try again in a few moments.');
    }
}
开发者ID:jpopgravitate,项目名称:grav-gforms-and-s3,代码行数:28,代码来源:gfs3.php

示例7: getBucketContents

 /**
  * Get S3 bucket contents (from cache if possible)
  *
  * @return array
  */
 private function getBucketContents()
 {
     $cacheFile = $this->cacheDir . '/s3browser-' . $this->s3Bucket;
     $contents = null;
     // get from cache if valid
     if ($this->cacheDuration && file_exists($cacheFile)) {
         $cacheAge = time() - filectime($cacheFile);
         if ($cacheAge < $this->cacheDuration) {
             $contents = unserialize(file_get_contents($cacheFile));
         }
     }
     // hit s3 if we didn't have anything cached
     if (!$contents) {
         $s3 = new S3($this->s3AccessKey, $this->s3SecretKey, $this->s3useSSL, $this->s3endPoint);
         $contents = $s3->getBucket($this->s3Bucket);
         // we weren't able to access the bucket
         if (!is_array($contents)) {
             return null;
         }
         // save if caching is enabled
         if ($this->cacheDuration) {
             file_put_contents($cacheFile, serialize($contents));
         }
     }
     return $contents;
 }
开发者ID:powdahound,项目名称:s3browser,代码行数:31,代码来源:S3Browser.php

示例8: upload

		function upload($localFilepath = 'path/to/file.jpg',$s3Path = 'tmp/', $filename = 'filename.jpg',$bucket = 'idc_files'){

			// $filename is the name that we want to save it as
			// - this is going to be something unique every time

			// Import Vendor file
			App::import('Vendor', 'S3', array('file' => 'S3'.DS.'s3.php'));

			// Instantiate the S3 class
			$s3 = new S3(AWS_ACCESS_KEY, AWS_SECRET_KEY); // defined in bootstrap.php

			// Ensure $newPath is valid
			if(substr($s3Path,-1,1) != '/'){
				$s3Path .= '/';
			}

			// Intended directory
			// - buckets are like the C: drive
			$intendedPath = $s3Path.$filename;

			// Put our file (also with public read access)
			if ($s3->putObjectFile($localFilepath, $bucket, $intendedPath, S3::ACL_PUBLIC_READ)) {
					//echo "S3::putObjectFile(): File copied to {$bucket}/".baseName($uploadFile).PHP_EOL;
					return 1;
			} else {
					return 0;
			}

			exit;   

		}
开发者ID:ryankanno,项目名称:Twilio-State-Machine,代码行数:31,代码来源:amazons3.php

示例9: put

 public function put($file, $name = null)
 {
     if (empty($name)) {
         $name = str_replace("\\", '/', str_replace(PHPFOX_DIR, '', $file));
     }
     return $this->_obj->putObjectFile($file, $this->_bucket, $name, \S3::ACL_PUBLIC_READ);
 }
开发者ID:mepsteinj,项目名称:phpfox-amazons3,代码行数:7,代码来源:CDN.php

示例10: deleteFile

 function deleteFile($filename)
 {
     $s3svc = new S3();
     // Removing the first slash is important - otherwise the URL is different.
     $aws_filename = eregi_replace('^/', '', $filename);
     $s3svc->deleteObject($aws_filename, MIRROR_S3_BUCKET);
     unset($s3svc);
 }
开发者ID:nonfiction,项目名称:nterchange,代码行数:8,代码来源:s3_mirror.php

示例11: _getS3

 /**
  * Returns a fresh S3 instance
  */
 private function _getS3($cfg)
 {
     $s3 = new S3($cfg['accesskey'], $cfg['secretkey']);
     if (!empty($cfg['endpoint'])) {
         $s3->setEndpoint($cfg['endpoint']);
     }
     return $s3;
 }
开发者ID:shelsonjava,项目名称:datawrapper,代码行数:11,代码来源:plugin.php

示例12: image

 public function image()
 {
     $image = new Image('http://sinastorage.com/sandbox/test.jpg');
     $image->rotate(50);
     $s3 = new S3();
     $result = $s3->plainWrite('test.jpg', $image->getContent(), $image->getSize(), $image->getMimeType());
     Common::debug($result);
 }
开发者ID:guojianing,项目名称:dagger2,代码行数:8,代码来源:DefaultController.php

示例13: execute

 public function execute()
 {
     $this->AWS_ACCESS_KEY = 'YOUR_AWS_ACCESS_KEY';
     $this->AWS_SECRET_KEY = 'YOUR_AWS_SECRET_KEY';
     $this->AWS_S3_BUCKET = 'YOUR_AWS_S3_BUCKET';
     $this->AWS_S3_PUBLIC = true;
     $this->AWS_S3_SSL = false;
     $s3 = new S3();
     $s3->setAuth($this->AWS_ACCESS_KEY, $this->AWS_SECRET_KEY);
     $s3->useSSL = $this->AWS_S3_SSL;
     // In my situation the images were in two different S3 buckets already. It will search these locations to try and find it.
     // Your images are probably local already, so you may need to modify the code further down to work with local directories.
     //$s3Buckets = array(...);
     $dbw = wfGetDB(DB_MASTER);
     $counter = 0;
     $iIncrement = 10000;
     for ($i = 0;; $i += $iIncrement) {
         $res = $dbw->select(array('image', 'imagelinks', 'page'), array('image.img_name', 'image.img_path', 'page.page_title'), 'image.img_name = imagelinks.il_to and imagelinks.il_from = page.page_id and page.page_namespace = 0 limit ' . $i . ', ' . $iIncrement, array());
         if (!$res) {
             echo 'No for rows.\\n';
             exit;
         }
         $logoPath = '';
         foreach ($res as $row) {
             echo "counter:{$counter}\n";
             echo "i:{$i}\n";
             ++$counter;
             if (!$row->img_name || !$row->img_path) {
                 continue;
             }
             echo 'img_name:' . $row->img_name . "\n";
             echo 'img_path:' . $row->img_path . "\n";
             echo 'page_title:' . $row->page_title . "\n";
             $file = wfFindFile($row->img_name, array());
             if ($file) {
                 $path = $file->getFullUrl();
                 $path = str_replace('http://s3.amazonaws.com/' . $this->AWS_S3_BUCKET . '/', '', $path);
                 echo "path:{$path}\n";
                 // If you have images that are already stored locally, you will need to modify this section. Instead of an S3::copyObject you
                 // may need to use the S3::putObject method to upload your local copy.
                 foreach ($s3Buckets as $s3Bucket) {
                     if ($s3->copyObject($s3Bucket, $row->img_path, $this->AWS_S3_BUCKET, $path, $this->AWS_S3_PUBLIC ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE)) {
                         echo 'SUCCESS:' . $row->img_name . "\n";
                         break;
                     } else {
                         echo 'ERROR1:' . $row->img_name . "\n";
                     }
                 }
             } else {
                 echo 'ERROR2:' . $row->img_name . "\n";
             }
             echo "\n";
         }
     }
 }
开发者ID:robksawyer,项目名称:lathe.tools,代码行数:55,代码来源:currentImagesToS3Migration.php

示例14: process_s3_copy

 function process_s3_copy($s3file, $accesskey, $secretkey, $bucket, $directory)
 {
     pb_backupbuddy::set_greedy_script_limits();
     require_once pb_backupbuddy::plugin_path() . '/lib/s3/s3.php';
     $s3 = new S3($accesskey, $secretkey);
     $destination_file = ABSPATH . 'wp-content/uploads/backupbuddy_backups/' . $s3file;
     if (file_exists($destination_file)) {
         $destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file);
     }
     $s3->getObject($bucket, $directory . $s3file, $destination_file);
 }
开发者ID:sonnetmedia,项目名称:otherpress.com,代码行数:11,代码来源:cron.php

示例15: 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


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