本文整理汇总了PHP中S3::putBucket方法的典型用法代码示例。如果您正苦于以下问题:PHP S3::putBucket方法的具体用法?PHP S3::putBucket怎么用?PHP S3::putBucket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类S3
的用法示例。
在下文中一共展示了S3::putBucket方法的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;
}
}
}
示例2: 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.');
}
}
示例3: init
/**
* Uses the init action to catch changes in the schedule and pass those on to the scheduler.
*
*/
function init()
{
if (isset($_POST['s3b-schedule'])) {
wp_clear_scheduled_hook('s3-backup');
if ($_POST['s3b-schedule'] != 'disabled') {
wp_schedule_event(time(), $_POST['s3b-schedule'], 's3-backup');
}
}
if (isset($_POST['s3-new-bucket']) && !empty($_POST['s3-new-bucket'])) {
include_once 'S3.php';
$_POST['s3-new-bucket'] = strtolower($_POST['s3-new-bucket']);
$s3 = new S3(get_option('s3b-access-key'), get_option('s3b-secret-key'));
$s3->putBucket($_POST['s3-new-bucket']);
$buckets = $s3->listBuckets();
if (is_array($buckets) && in_array($_POST['s3-new-bucket'], $buckets)) {
update_option('s3b-bucket', $_POST['s3-new-bucket']);
$_POST['s3b-bucket'] = $_POST['s3-new-bucket'];
} else {
update_option('s3b-bucket', false);
}
}
if (!get_option('s3b-bucket')) {
add_action('admin_notices', array('WPS3B', 'newBucketWarning'));
}
}
示例4: sprintf
/**
* Creates bucket
*
* @param string $container_id
* @param string $error
* @return boolean
*/
function create_container(&$container_id, &$error)
{
if (!$this->_init($error)) {
return false;
}
$this->_set_error_handler();
$buckets = @$this->_s3->listBuckets();
if ($buckets === false) {
$error = sprintf('Unable to list buckets (%s).', $this->_get_last_error());
$this->_restore_error_handler();
return false;
}
if (in_array($this->_config['bucket'], (array) $buckets)) {
$error = sprintf('Bucket already exists: %s.', $this->_config['bucket']);
$this->_restore_error_handler();
return false;
}
if (empty($this->_config['bucket_acl'])) {
$this->_config['bucket_acl'] = S3::ACL_PRIVATE;
}
if (!isset($this->_config['bucket_location'])) {
$this->_config['bucket_location'] = S3::LOCATION_US;
}
if (!@$this->_s3->putBucket($this->_config['bucket'], $this->_config['bucket_acl'], $this->_config['bucket_location'])) {
$error = sprintf('Unable to create bucket: %s (%s).', $this->_config['bucket'], $this->_get_last_error());
$this->_restore_error_handler();
return false;
}
$this->_restore_error_handler();
return true;
}
示例5: onImageAddition
public function onImageAddition(ImageAdditionEvent $event)
{
global $config;
$access = $config->get_string("amazon_s3_access");
$secret = $config->get_string("amazon_s3_secret");
$bucket = $config->get_string("amazon_s3_bucket");
if (!empty($bucket)) {
log_debug("amazon_s3", "Mirroring Image #" . $event->image->id . " to S3 #{$bucket}");
$s3 = new S3($access, $secret);
$s3->putBucket($bucket, S3::ACL_PUBLIC_READ);
$s3->putObjectFile(warehouse_path("thumbs", $event->image->hash), $bucket, 'thumbs/' . $event->image->hash, S3::ACL_PUBLIC_READ, array(), array("Content-Type" => "image/jpeg", "Content-Disposition" => "inline; filename=image-" . $event->image->id . ".jpg"));
$s3->putObjectFile(warehouse_path("images", $event->image->hash), $bucket, 'images/' . $event->image->hash, S3::ACL_PUBLIC_READ, array(), array("Content-Type" => $event->image->get_mime_type(), "Content-Disposition" => "inline; filename=image-" . $event->image->id . "." . $event->image->ext));
}
}
示例6: __construct
/**
* Constructor
*
* @return void
*/
protected function __construct()
{
require_once LC_DIR_MODULES . 'CDev' . LC_DS . 'AmazonS3Images' . LC_DS . 'lib' . LC_DS . 'S3.php';
$config = \XLite\Core\Config::getInstance()->CDev->AmazonS3Images;
if ($config->access_key && $config->secret_key && function_exists('curl_init')) {
try {
$this->client = new \S3($config->access_key, $config->secret_key);
\S3::setExceptions(true);
if (!$this->client->getBucketLocation($config->bucket)) {
$this->client->putBucket($config->bucket);
}
$this->valid = true;
} catch (\S3Exception $e) {
\XLite\Logger::getInstance()->registerException($e);
}
}
}
示例7: 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);
}
示例8: MoveToS3
function MoveToS3($strPath, $strFileName, $strType, $strS3Path)
{
rtrim($strPath, '/');
rtrim($strS3Path, '/');
if (file_exists($strPath . '/' . $strFileName)) {
require_once __DOCROOT__ . __PHP_ASSETS__ . '/s3.class.php';
$objS3 = new S3();
$objS3->putBucket(AWS_BUCKET);
$fh = fopen($strPath . '/' . $strFileName, 'rb');
$contents = fread($fh, filesize($strPath . '/' . $strFileName));
fclose($fh);
$objS3->putObject($strFileName, $contents, AWS_BUCKET . $strS3Path, 'public-read', $strType);
unlink($strPath . '/' . $strFileName);
unset($objS3);
return true;
} else {
return false;
}
}
示例9: buckets
/**
* Creates bucket
*
* @param string $error
* @return boolean
*/
function create_bucket(&$error)
{
if (!$this->_init($error)) {
return false;
}
$buckets = @$this->_s3->listBuckets();
if (!$buckets) {
$error = 'Unable to list buckets (check your credentials).';
return false;
}
if (in_array($this->_config['bucket'], (array) $buckets)) {
$error = sprintf('Bucket already exists: %s.', $this->_config['bucket']);
return false;
}
if (!@$this->_s3->putBucket($this->_config['bucket'], S3::ACL_PUBLIC_READ)) {
$error = sprintf('Unable to create bucket: %s.', $this->_config['bucket']);
return false;
}
return true;
}
示例10:
function upload_to_amazon($source_filename, $dest_filename, $image_type = IMAGETYPE_JPEG, $compression = 75, $permissions = null)
{
// Create local instance of image
$this->save($source_filename, $image_type, $compression, $permissions);
// Begin s3 sequence
$s3 = new S3('AMAZON_ACCESS_TOKEN', 'AMAZON_SECRET_TOKEN');
// Name each bucket off the domain
$bucket = 'screenbin';
// Make sure the bucket is there
if (!in_array($bucket, $s3->listBuckets())) {
$s3->putBucket($bucket, S3::ACL_PUBLIC_READ);
}
// Upload to s3
if ($s3->putObjectFile($source_filename, $bucket, $dest_filename, S3::ACL_PUBLIC_READ)) {
// Delete local version of the file
return true;
} else {
return false;
}
}
示例11: foreach
//.........这里部分代码省略.........
break;
case 'unix':
$fsFactory = new FilesystemFactory($permFactory);
break;
case 'windows':
$fsFactory = new WindowsFilesystemFactory();
break;
}
$manager = new FTPFilesystemManager($wrapper, $fsFactory);
$dlVoter = new DownloaderVoter();
$ulVoter = new UploaderVoter();
$ulVoter->addDefaultFTPUploaders($wrapper);
$crVoter = new CreatorVoter();
$crVoter->addDefaultFTPCreators($wrapper, $manager);
$deVoter = new DeleterVoter();
$deVoter->addDefaultFTPDeleters($wrapper, $manager);
$ftp = new FTP($manager, $dlVoter, $ulVoter, $crVoter, $deVoter);
if (!$ftp) {
$this->b['error'] = _("Error creating the FTP object");
backup_log($this->b['error']);
return;
}
if (!$ftp->directoryExists(new Directory($path))) {
backup_log(sprintf(_("Creating directory '%s'"), $path));
try {
$ftp->create(new Directory($path), array(FTP::RECURSIVE => true));
} catch (\Exception $e) {
$this->b['error'] = sprintf(_("Directory '%s' did not exist and we could not create it"), $path);
backup_log($this->b['error']);
backup_log($e->getMessage());
return;
}
}
try {
backup_log(_("Saving file to remote ftp"));
$ftp->upload(new File($path . '/' . $this->b['_file'] . '.tgz'), $this->b['_tmpfile']);
} catch (\Exception $e) {
$this->b['error'] = _("Unable to upload file to the remote server");
backup_log($this->b['error']);
backup_log($e->getMessage());
return;
}
//run maintenance on the directory
$this->maintenance($s['type'], $path, $ftp);
break;
case 'awss3':
//subsitute variables if nesesary
$s['bucket'] = backup__($s['bucket']);
$s['awsaccesskey'] = backup__($s['awsaccesskey']);
$s['awssecret'] = backup__($s['awssecret']);
$awss3 = new \S3($s['awsaccesskey'], $s['awssecret']);
// Does this bucket already exist?
$buckets = $awss3->listBuckets();
if (!in_array($s['bucket'], $buckets)) {
// Create the bucket
$awss3->putBucket($s['bucket'], \S3::ACL_PUBLIC_READ);
}
//copy file
if ($awss3->putObjectFile($this->b['_tmpfile'], $s['bucket'], $this->b['name'] . "/" . $this->b['_file'] . '.tgz', \S3::ACL_PUBLIC_READ)) {
dbug('S3 successfully uploaded your backup file.');
} else {
dbug('S3 failed to accept your backup file');
}
//run maintenance on the directory
$this->maintenance($s['type'], $s, $awss3);
break;
case 'ssh':
//subsitute variables if nesesary
$s['path'] = backup__($s['path']);
$s['user'] = backup__($s['user']);
$s['host'] = backup__($s['host']);
$destdir = $s['path'] . '/' . $this->b['_dirname'];
//ensure directory structure
$cmd = fpbx_which('ssh') . ' -o StrictHostKeyChecking=no -i ';
$cmd .= $s['key'] . " -l " . $s['user'] . ' ' . $s['host'] . ' -p ' . $s['port'];
$cmd .= " 'mkdir -p {$destdir}'";
exec($cmd, $output, $ret);
if ($ret !== 0) {
backup_log("SSH Error ({$ret}) - Received " . json_encode($output) . " from {$cmd}");
}
$output = null;
//put file
// Note that SCP (*unlike SSH*) needs IPv6 addresses in ['s. Consistancy is awesome.
if (filter_var($s['host'], \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
$scphost = "[" . $s['host'] . "]";
} else {
$scphost = $s['host'];
}
$cmd = fpbx_which('scp') . ' -o StrictHostKeyChecking=no -i ' . $s['key'] . ' -P ' . $s['port'];
$cmd .= " " . $this->b['_tmpfile'] . " " . $s['user'] . "@{$scphost}:{$destdir}";
exec($cmd, $output, $ret);
if ($ret !== 0) {
backup_log("SCP Error ({$ret}) - Received " . json_encode($output) . " from {$cmd}");
}
//run maintenance on the directory
$this->maintenance($s['type'], $s);
break;
}
}
}
示例12: define
<?php
// Bucket Name
$bucket = "communitycloud1";
if (!class_exists('S3')) {
require_once 'library/S3.php';
}
//AWS access info
if (!defined('awsAccessKey')) {
define('awsAccessKey', 'AKIAI26EDFLOQPYCL26A');
}
if (!defined('awsSecretKey')) {
define('awsSecretKey', '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');
}
try {
$s3 = new S3(awsAccessKey, awsSecretKey);
$s3->putBucket($bucket, S3::ACL_PUBLIC_READ);
$s3->listBuckets();
} catch (Exception $e) {
echo $e->getMessage();
}
示例13: taskDownload
//.........这里部分代码省略.........
}
$types = $cq->getTypeArr($case_list['Easycase']['type_id'], $GLOBALS['TYPE']);
if (count($types)) {
$tasktype = $types['Type']['name'];
}
//}
$arr = '';
$arr[] = $title = str_replace('"', '""', $case_list['Easycase']['title']);
$arr[] = $description = strip_tags(str_replace('"', '""', $case_list['Easycase']['message']));
$arr[] = $status;
$arr[] = $priority;
$arr[] = $tasktype;
if ($case_list['User3']['Assigned_to']) {
$Assigned = $case_list['User3']['Assigned_to'];
} else {
$Assigned = $case_list['User1']['created_by'];
}
$arr[] = $Assigned;
$arr[] = $crby = $case_list['User1']['created_by'];
$arr[] = $updateby = $case_list['User2']['updated_by'];
$tz = $view->loadHelper('Tmzone');
$temp_dat = $tz->GetDateTime(SES_TIMEZONE, TZ_GMT, TZ_DST, TZ_CODE, $case_list['Easycase']['actual_dt_created'], "datetime");
$arr[] = $crted = date('m/d/Y H:i:s', strtotime($temp_dat));
//$arr[] = $crted =date('m/d/Y H:i:s', strtotime($case_list['Easycase']['actual_dt_created']));
$estmthrs = '';
$hrspent = '';
if ($case_list['Easycase']['istype'] == 1) {
$estmthrs = $estimated_hours;
$hrspent = $hours;
} else {
$estimated_hours = '';
$hrspent = $case_list['Easycase']['hours'];
}
$arr[] = $estimated_hours;
$arr[] = $hrspent;
$easycaseids[] = $case_list['Easycase']['id'];
$retval = fputcsv($file, $arr);
//$csv_output .= $title.",".$status.",".$priority.",".$tasktype.",".$description.",".$Assigned.",".$crby.",".$updateby.",".$estmthrs.",".$hrspent.",".$crted.",".$modified;
}
fclose($file);
if ($retval) {
$filesarr = ClassRegistry::init('CaseFile')->find('all', array('conditions' => array('CaseFile.easycase_id' => $easycaseids, 'CaseFile.project_id' => $ProjId, 'CaseFile.company_id' => SES_COMP)));
if ($filesarr) {
foreach ($filesarr as $k => $value) {
if ($value['CaseFile']['downloadurl']) {
if (!isset($fp)) {
$fp = fopen(DOWNLOAD_TASK_PATH . $folder_name . '/cloud.txt', 'a+');
}
fwrite($fp, "\n\t" . $value['CaseFile']['downloadurl'] . "\n");
$temp_url = $value['CaseFile']['downloadurl'];
} else {
if (!file_exists(DOWNLOAD_TASK_PATH . $folder_name . '/attachments')) {
mkdir(DOWNLOAD_TASK_PATH . $folder_name . "/attachments", 0777, true);
}
$temp_url = $frmt->generateTemporaryURL(DIR_CASE_FILES_S3 . $value['CaseFile']['file']);
$img = DOWNLOAD_TASK_PATH . $folder_name . "/attachments/" . $value['CaseFile']['file'];
$resp = file_put_contents($img, file_get_contents($temp_url));
}
}
if (isset($fp)) {
fclose($fp);
}
}
$zipfile_name = strtoupper($projShorName) . '_TASK_' . $curCaseNo . "_" . $curdt . '.zip';
$zipfile = DOWNLOAD_TASK_PATH . 'zipTask/' . $zipfile_name;
$return = $this->Format->zipFile(DOWNLOAD_TASK_PATH . $folder_name, $zipfile, 1);
if ($return) {
if (file_exists(DOWNLOAD_TASK_PATH . $folder_name)) {
@array_map('unlink', glob(DOWNLOAD_TASK_PATH . $folder_name . "/attachments/*"));
@rmdir(DOWNLOAD_TASK_PATH . $folder_name . '/attachments');
@array_map('unlink', glob(DOWNLOAD_TASK_PATH . $folder_name . "/*"));
$isdel = rmdir(DOWNLOAD_TASK_PATH . $folder_name);
}
if (USE_S3 == 0) {
$download_url = HTTP_ROOT . DOWNLOAD_S3_TASK_PATH . $zipfile_name;
$this->set('downloadurl', $download_url);
} else {
$s3 = new S3(awsAccessKey, awsSecretKey);
$s3->putBucket(DOWNLOAD_BUCKET_NAME, S3::ACL_PRIVATE);
$download_url = DOWNLOAD_S3_TASK_PATH . $zipfile_name;
$s3_download_url = "https://s3.amazonaws.com/" . DOWNLOAD_BUCKET_NAME . '/' . DOWNLOAD_S3_TASK_PATH . $zipfile_name;
$returnvalue = $s3->putObjectFile(DOWNLOAD_S3_TASK_PATH . $zipfile_name, DOWNLOAD_BUCKET_NAME, $download_url, S3::ACL_PUBLIC_READ);
if ($returnvalue) {
unlink(DOWNLOAD_S3_TASK_PATH . $zipfile_name);
}
$this->set('downloadurl', $s3_download_url);
}
$this->set('projName', $ProjName);
$this->set('projId', $ProjId);
$this->set('caseUid', $caseUniqId);
$this->set('caseNum', $curCaseNo);
$this->set('taskTitle', $taskTitle);
$this->set('zipfilename', $zipfile_name);
} else {
$this->set('derror', 'Opps! Error occured in creation of zip file.');
}
} else {
$this->set('derror', 'Opps! Error occured in creating the task csv file.');
}
}
示例14: logxx
}
}
logxx("Total backup size:" . $bsize);
####### STARING AMAZON S3 MODE
if ($_CONFIG['cron_amazon_active']) {
include_once "classes/S3.php";
logxx();
if (!$_CONFIG['cron_amazon_ssl']) {
$amazon_ssl = false;
} else {
$amazon_ssl = true;
}
$s3 = new S3($_CONFIG['cron_amazon_awsAccessKey'], $_CONFIG['cron_amazon_awsSecretKey'], $amazon_ssl);
logxx("AMAZON S3: Starting communication with the Amazon S3 server...ssl mode " . (int) $amazon_ssl);
$buckets = $s3->listBuckets();
if ($s3->putBucket($_CONFIG['cron_amazon_bucket'], "private") || @in_array($_CONFIG['cron_amazon_bucket'], $buckets)) {
if ($s3->putObjectFile($clonerPath . "/" . $file, $_CONFIG['cron_amazon_bucket'], $_CONFIG['cron_amazon_dirname'] . "/" . baseName($file), "private")) {
logxx("AMAZON S3: File copied to {" . $_CONFIG['cron_amazon_bucket'] . "}/" . $_CONFIG['cron_amazon_dirname'] . "/" . $file);
} else {
logxx("AMAZON S3: Failed to copy file to {" . $_CONFIG['cron_amazon_bucket'] . "}/" . $_CONFIG['cron_amazon_dirname'] . "/" . $file);
exit;
}
} else {
logxx("AMAZON S3: Unable to create bucket " . $_CONFIG['cron_amazon_bucket'] . " (it may already exist and/or be owned by someone else)!");
exit;
}
}
###### END
####### STARING DROPBOX MODE
if ($_CONFIG['cron_dropbox_active']) {
include_once "classes/DropboxClient.php";
示例15: define
//AWS access info
if (!defined('awsAccessKey')) {
define('awsAccessKey', 'CHANGETHIS');
}
if (!defined('awsSecretKey')) {
define('awsSecretKey', 'CHANGETHISTOO');
}
$s3 = new S3('', '');
//check whether a form was submitted
if (isset($_POST['Submit'])) {
//retreive post variables
$fileName = $_FILES['theFile']['name'];
$fileTempName = $_FILES['theFile']['tmp_name'];
$fileSize = $_FILES['theFile']['size'];
$fileUrl = "https://s3-eu-west-1.amazonaws.com/photo-upload/" . $fileName;
$s3->putBucket("photo-upload", S3::ACL_PUBLIC_READ);
//move the file
if ($s3->putObjectFile($fileTempName, "photo-upload", $fileName, S3::ACL_PUBLIC_READ)) {
echo "We successfully uploaded your file.";
} else {
echo "Something went wrong while uploading your file... sorry.";
}
}
$sql = "UPDATE Owner \nSET Owner_img_path='" . $fileUrl . "'\nWHERE Owner_uname='" . $uname . "'";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully. Last inserted ID is: " . $last_id;
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close();
?>