title: export mysql table to csv with php (no select into outfile)
body: <p>I am trying to export a MySQL table to a CSV file.
  The code I have works fine:</p>
  
  <pre><code>$result = mysql_query('SELECT * FROM `TABLE`'); 
  if (!$result) die('Couldn\'t fetch records'); 
  $num_fields = mysql_num_fields($result); 
  $headers = array(); 
  for ($i = 0; $i &lt; $num_fields; $i++) 
  {     
  $headers[] = mysql_field_name($result , $i); 
  } 
  $fp = fopen('php://output', 'w'); 
  if ($fp &amp;&amp; $result) 
  {     
  header('Content-Type: text/csv');
  header('Content-Disposition: attachment; filename="export.csv"');
  header('Pragma: no-cache');    
  header('Expires: 0');
  fputcsv($fp, $headers); 
  while ($row = mysql_fetch_row($result)) 
  {
  fputcsv($fp, array_values($row)); 
  }
  die; 
  }
  </code></pre>
  
  <p>However I would like to have the csv file uploaded automatically to my web host server instead of being downloaded to my computer.<br>
  I can't use the "SELECT... INTO OUTFILE" query as my provider does not want to give me the FILE privilege.<br>
  Any way I can wright the csv output to my provider's server with php instead of downloading it to my computer?</p>