Tamer Zoubi @ Drupal 8


Drupal expert | Programmer

Amazon S3

Check if a file exists in Amazon S3

If you are looking for a way to check if a file exists in Amazon S3 bucket using Amazon S3 PHP library, then probably this may help you.

Simplest way is to use function getObjectInfo()

<?php
//initiate the class
$s3 = new AmazonS3();
$info = $s3->getObjectInfo($bucket, $filename);
if ($info){
//File exists
}
else{
//File doesn't exists
}
?>

This function will return FALSE if $filename doesn't exists in Amazon S3 bucket.

Tags
php
Amazon S3