S3::putObjectString PHP Method

putObjectString() public static method

Put an object from a string (legacy function)
public static putObjectString ( string $string, string $bucket, string $uri, constant $acl = self::ACL_PRIVATE, array $metaHeaders = [], string $contentType = 'text/plain' ) : boolean
$string string Input data
$bucket string Bucket name
$uri string Object URI
$acl constant ACL constant
$metaHeaders array Array of x-amz-meta-* headers
$contentType string Content type
return boolean
    public static function putObjectString($string, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = 'text/plain')
    {
        return self::putObject($string, $bucket, $uri, $acl, $metaHeaders, $contentType);
    }

Usage Example

Example #1
0
 /**
  * Tests S3
  *
  * @param string $error
  * @return boolean
  */
 function test(&$error)
 {
     if (!parent::test($error)) {
         return false;
     }
     $string = 'test_s3_' . md5(time());
     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 doesn\'t exist: %s.', $this->_config['bucket']);
         $this->_restore_error_handler();
         return false;
     }
     if (!@$this->_s3->putObjectString($string, $this->_config['bucket'], $string, S3::ACL_PUBLIC_READ)) {
         $error = sprintf('Unable to put object (%s).', $this->_get_last_error());
         $this->_restore_error_handler();
         return false;
     }
     if (!($object = @$this->_s3->getObject($this->_config['bucket'], $string))) {
         $error = sprintf('Unable to get object (%s).', $this->_get_last_error());
         $this->_restore_error_handler();
         return false;
     }
     if ($object->body != $string) {
         $error = 'Objects are not equal.';
         @$this->_s3->deleteObject($this->_config['bucket'], $string);
         $this->_restore_error_handler();
         return false;
     }
     if (!@$this->_s3->deleteObject($this->_config['bucket'], $string)) {
         $error = sprintf('Unable to delete object (%s).', $this->_get_last_error());
         $this->_restore_error_handler();
         return false;
     }
     $this->_restore_error_handler();
     return true;
 }
All Usage Examples Of S3::putObjectString