title: Amazon S3 PHP Stream Wrapper Set Public View Permissions for Image
body: <p>I'm using the Amazon PHP SDK for S3 to save images to a bucket.  I need to make sure that every image that gets added is publicly viewable, but I don't want to add list accessibility.  I couldn't find a way to set this at the bucket level so that it propagated to all the uploaded images.</p>
  
  <p>So, my question is, how do I set the permissions on the image after I move it to S3 so that it can be viewed in a browser?</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>require_once("aws/aws-autoloader.php");
  
  // Amazon S3
  use Aws\S3\S3Client;
  
  // Create an Amazon S3 client object
  $s3Client = S3Client::factory(array(
      'key'    =&gt; $amazonKey,
      'secret' =&gt; $amazonSecret
  ));
  
  // Register the stream wrapper from a client object
  $s3Client-&gt;registerStreamWrapper();
  
  // Save Thumbnail
  $s3Path = "s3://".$amazonBucket."/".$folderYear."/".$folderMonth."/";
  $s3Stream = fopen($s3Path . $thumbnail, 'w');
  fwrite($s3Stream,$thumb_content);
  @fclose($s3Stream);
  </code></pre>
  
  <p>I just need help after the image has been saved, how can I make sure the image is publicly viewable but the bucket and folders do not list all the contents.</p>