title: How do I prompt the user to download a PHP-generated .CSV file, and how should I handle deleting it?
body: <p>Here's my PHP code to create a .CSV file based on some SQL data. It's working as intended, the only issue being that <strong>it simply creates a .CSV file on the server, and doesn't prompt the user to download it</strong>.</p>
  
  <pre><code>&lt;?php
      require_once "../assets/repository/mysql.php";
  
      $query = "SELECT * FROM datashep_AMS.COMPLETE_APPLICATIONS";
      $results = mysql_query($query);
  
      $first = true;
  
      $out = fopen('export.csv', 'w');
  
      while($row = mysql_fetch_assoc($results)){
          if($first){
              $titles = array();
              foreach($row as $key=&gt;$val){
                  $titles[] = $key;
              }
              fputcsv($out, $titles);
              $first = false;
          }
          fputcsv($out, $row);
      }
  
      fclose($out);
  ?&gt;
  </code></pre>
  
  <p>So my question is, how do I make the user download the file immediately upon it being generated?</p>
  
  <p>And, once they've downloaded it (or declined), how should I handle deleting the .CSV file from my server?</p>