title: Download file stored on Amazon S3 with php
body: <p>I have the following code which successfully displays a file saved on S3 to the browser, but I would like to be able to download the file to the client's computer.</p>
  
  <p>What do I need to do?</p>
  
  <pre><code>$result = S3::getObject($Bucketname,$uri);
  header("Content-Type: ".$result-&gt;headers['type']);
  die($result-&gt;body);
  </code></pre>
  
  <p>I've tried the following, but it just downloads an unreadable file...</p>
  
  <pre><code>$result = S3::getObject($Bucketname,$uri);
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename=test.pdf');
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
  header('Content-Length: ' . strlen($result-&gt;body));
  ob_clean();
  flush();
  readfile($result-&gt;body);
  exit;
  </code></pre>