title: Download files from AWS S3 to client system
body: <p>I am trying to provide download file option to my users. I am working on <code>AWS EC2</code> with <code>AWS PHP SDK V2.8</code>. I am able to display images on my website. I try according to question <a href="https://stackoverflow.com/questions/870215/force-download-with-php-on-amazon-s3">force-download-with-php-on-amazon-s3</a> but no success. Most of the answer of this question are pretty old. I am using below code for uploading</p>
  
  <pre><code>try {
      $result = $s3-&gt;putObject(array(
         'Bucket' =&gt; $bucketName,
         'ACL' =&gt; 'authenticated-read',
         'Key' =&gt; "s3112.png",
         'ServerSideEncryption' =&gt; 'AES256',
          'SourceFile' =&gt; $filepath,
         'ContentType' =&gt; mime_content_type($filepath),
          'debug' =&gt; [
            'logfn' =&gt; function ($msg) {
                 echo $msg . "\n";
             },
              'stream_size' =&gt; 0,
             'scrub_auth' =&gt; true,
             'http' =&gt; true,
         ],
     ));
  } catch (S3Exception $e) {
     echo $e-&gt;getMessage() . "\n";
  }
  </code></pre>
  
  <p>Here is what is tried.</p>
  
  <pre><code>header('Content-disposition: attachment; filename=s3112.png');
  header('Content-type: image/png');
  readfile("https://s3-ap-southeast-1.amazonaws.com/mytest.sample/s3112.png");
  
  //header("Location: https://s3-ap-southeast-1.amazonaws.com/mytest.sample/s3112.png");
  //// Location redirection to a MP3 that lets the browser decide what to do.
  //header("Location:  https://s3-ap-southeast-1.amazonaws.com/mytest.sample/s3112.png");
  </code></pre>
  
  <p>I tried with</p>
  
  <pre><code> &lt;a href="https://s3-ap-southeast-1.amazonaws.com/mytest.sample/s3112.png" download&gt; 
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/l1gib.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l1gib.png" alt="enter image description here"></a></p>
  
  <p>but no success. Any help appreciate. </p>