Exemplo n.º 1
0
 public function exists()
 {
     if ($this->get('path')) {
         return $this->client->doesObjectExist(AMAZON_S3_BUCKET_NAME, $this->get('path'));
     }
     return false;
 }
Exemplo n.º 2
0
 public function exists($path)
 {
     try {
         return $this->_client->doesObjectExist($this->_bucket, $this->_getAbsolutePath($path));
     } catch (\Exception $e) {
         throw new CM_Exception('Cannot check existence of `' . $path . '`: ' . $e->getMessage());
     }
 }
Exemplo n.º 3
0
 public function exists($path)
 {
     try {
         return $this->_client->doesObjectExist($this->_bucket, $this->_getAbsolutePath($path));
     } catch (\Exception $e) {
         throw new CM_Exception('Cannot check existence of path', null, ['path' => $path, 'originalExceptionMessage' => $e->getMessage()]);
     }
 }
Exemplo n.º 4
0
 http://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/basic-usage.html#creating-a-client
*/
$s3 = new Aws\S3\S3Client(['version' => '2006-03-01', 'region' => 'eu-central-1']);
/*
 Everything uploaded to Amazon S3 must belong to a bucket. These buckets are
 in the global namespace, and must have a unique name.

 For more information about bucket name restrictions, see:
 http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
*/
$bucket = 'kuchy';
$filename = 'orange-pi-one-pocitac-raspberry-pi-nestandard2.jpg';
$imgUrl = 'http://ipravda.sk/res/2016/01/30/thumbs/' . $filename;
$img = file_get_contents($imgUrl);
/*
 Files in Amazon S3 are called "objects" and are stored in buckets. A specific
 object is referred to by its key (i.e., name) and holds data. Here, we create
 a new object with the key "hello_world.txt" and content "Hello World!".

 For a detailed list of putObject's parameters, see:
 http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html#putobject
*/
$response = $s3->doesObjectExist($bucket, $filename);
if ($response) {
    echo 'Image already exist!' . "\r\n";
    echo 'url: https://s3.eu-central-1.amazonaws.com/kuchy/' . $filename . "\r\n";
} else {
    echo "Creating a new object with key {$filename}\n";
    $result = $s3->putObject(['Bucket' => $bucket, 'Key' => $filename, 'Body' => $img, 'ContentType' => 'image/jpeg', 'ACL' => 'public-read']);
    echo 'url: ' . $result['ObjectURL'] . "\r\n";
}