title: AWS S3 Internal Server Error: Tyring to upload pdf file on after another
body: <p>I'm trying to generate <strong>PDF</strong> file using <strong>FPDF and PHP</strong> and later upload to  <strong>AWS-s3</strong> and generate the <strong>url.</strong> When I executed the below code in my <strong>local-machine</strong> Using <strong>XAMPP</strong> it's generating files and uploading it to <strong>S3</strong>.</p>
  
  <p>But When I deployed in <strong>AWS server as an API</strong> it's uploading only first file and for other its giving <strong>500 server error</strong></p>
  
  <p><strong>Below is my code that I used in Local Machine</strong></p>
  
  <pre><code>    require '../fpdf/fpdf.php';
      require 'start.php';
  
      use Aws\Exception\AwsException;
  
      $location = "bangalore";
      $db     =   getConnection();
      $query   = "SELECT first_name FROM customer_info where location = '$location'";
      $execute = $db-&gt;query($query);
      $result  = $execute-&gt;fetchAll(PDO::FETCH_ASSOC);
  
    for($i = 0; $i &lt; $len; $i++) {
   $pdf = new FPDF();
   $pdf-&gt;AddPage();
  
  $pdf-&gt;SetFont('Arial', 'B', 14);
  $txt = "Legal Document of ".$result[$i]['first_name'];
  $pdf-&gt;Cell(180, 0, $txt, 0, 1, 'C');
  $pdf-&gt;Line(5, 20, 200, 20);
  
  $docname = $result[$i]['first_name'] . ".pdf";
  $filepath = "../file/{$docname}";
  $pdf-&gt;Output($filepath, 'F');
  
  //s3 client
  try {
         $res = $S3-&gt;putObject([
          'Bucket' =&gt; $config['S3']['bucket'],
          'Key' =&gt; "PATH_TO_THE_DOCUMENT/{$docname}",
          'Body' =&gt; fopen($filepath, 'rb'),
          'ACL' =&gt; 'public-read'
      ]);
  
      var_dump($res["ObjectURL"]);
  } catch (S3Exception $e) {
      echo $e-&gt;getMessage() . "\n";
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>   Array ( [0] =&gt; Array ( [first_name] =&gt; Mohan ) [1] =&gt; Array ( [first_name] =&gt; Prem ) [2] =&gt; Array ( [first_name] =&gt; vikash ) [3] =&gt; Array ( [first_name] =&gt; kaushik ) )
  
       string(70) "https://streetsmartb2.s3.amazonaws.com/PATH_TO_THE FILE/Mohan.pdf" 
  
   string(72) "https://streetsmartb2.s3.amazonaws.com/PATH_TO_THE FILE/Prem%20.pdf" 
  </code></pre>
  
  <p><strong>API CODE</strong></p>
  
  <pre><code>      //pdf generation another api
        $app-&gt;post('/pdfmail', function() use($app){
  
      //post parameters
      $location = $app-&gt;request-&gt;post('loc');
      $id       = $app-&gt;request-&gt;post('id');
  
  
  
     $db = getConnection();
     $query   = "SELECT * FROM customer_info where location = '$location'";
    $execute = $db-&gt;query($query);
    $result  = $execute-&gt;fetchAll(PDO::FETCH_ASSOC);
    $len = sizeof($result);
  
    //request array
    $request = array();
  
    if($result != Null) {
        for($i = 0; $i &lt; $len; $i++) {
            $pdf = new FPDF();
            $pdf-&gt;AddPage();
  
            $pdf-&gt;SetFont('Arial', 'B', 14);
            $txt = "Document of Mr." . $result[$i]['first_name'];
            $pdf-&gt;Cell(180, 0, $txt, 0, 1, 'C');
            $pdf-&gt;Line(5, 20, 200, 20);
  
            $docname = $result[$i]['first_name'] . ".pdf";
            var_dump($docname);
            $filepath = "../file/{$docname}";
            var_dump($filepath);
            $pdf-&gt;Output($filepath, 'F');
  
  
            //s3 client
            require '../aws/aws-autoloader.php';
  
            $config = require('config.php');
  
  
            //create s3 instance
            $S3 = S3Client::factory([
                'version' =&gt; 'latest',
                'region' =&gt; 'REGION',
                'credentials' =&gt; array(
                    'key' =&gt; $config['S3']['key'],
                    'secret' =&gt; $config['S3']['secret']
                )
            ]);
  
  
  
            try {
                $res = $S3-&gt;putObject([
                    'Bucket' =&gt; $config['S3']['bucket'],
                    'Key' =&gt; "PATH_TO_FILE{$docname}",
                    'Body' =&gt; fopen($filepath, 'rb'),
                    'ACL' =&gt; 'public-read'
                ]);
                var_dump($res["ObjectURL"]);
            } catch (S3Exception $e) {
                echo $e-&gt;getMessage() . "\n";
            }
  
        }
    }
  </code></pre>
  
  <p><strong>OUTPUT WHEN TESTED IN POSTMAN</strong></p>
  
  <pre><code>    string(10) "vikash.pdf"
      string(18) "../file/vikash.pdf"
     string(71) "https://streetsmartb2.s3.amazonaws.com/PATH_TO_FILE/vikash.pdf"
    string(13) "pradeepan.pdf"
     string(21) "../file/pradeepan.pdf"
  </code></pre>
  
  <p><strong>After this I'm getting internal server error.</strong></p>