I have a php page that takes my query results and saves them to a csv, which then prompts to download the csv file (all which is working fine). What I need is for the file to save in the same location on the server but I cannot seem to get it to work. Any idea how to save to the server rather than download?
<?php
// Database Connection
include "connection.php"; //Connect to Database
// Fetch Record from Database
$output = "";
$sql = mysql_query("select '$select' from'$from' where'$where'"
$columns_total = mysql_num_fields($sql);
// Get The Field Name
for ($i = 0; $i < $columns_total; $i++) {
$heading = mysql_field_name($sql, $i);
$output .= '"'.$heading.'",';
}
$output .="\n";
// Get Records from the table
while ($row = mysql_fetch_array($sql)) {
for ($i = 0; $i < $columns_total; $i++) {
$output .='"'.$row["$i"].'",';
}
$output .="\n";
}
// Download the file
$filename = "file.csv";
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);
exit;
?>