Скачать SQL в CSV с помощью PHP
Я пытаюсь загрузить SQL-запрос в CSV-файл.
Приведенный ниже код работает, но не запускает диалоговое окно "Сохранить или открыть".
Файл ниже запускается по ссылке
<p><a href="TestDownload.php">Download</a></p>
Как вызвать диалоговое окно?
Что я уже пробовал:
<?php require_once('../Connections/PaSiteGuide.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } // output headers so that the file is downloaded rather than displayed header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=BOP.csv'); // create a file pointer connected to the output stream $output = fopen('php://output', 'w'); // output the column headings fputcsv($output, array('ID','Common Name', 'Scientific Name', 'Breeds', 'Abundance', 'Occurrence', 'Seasonal Status','AOU_Order ')); // fetch the data mysql_select_db($database_PaSiteGuide, $PaSiteGuide); $rows = mysql_query('SELECT BirdsOfPa.ID, BirdsOfPa.CommonName, BirdsOfPa.SciName, BirdsOfPa.Breeding, BirdsOfPa.Abundance, BirdsOfPa.Occurrence, BirdsOfPa.SeasonalStatus, AOU_List.AOU_Order FROM BirdsOfPa, AOU_List WHERE BirdsOfPa.ID = AOU_List.SPNO ORDER BY AOU_List.AOU_Order ASC'); // loop over the rows, outputting them while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row); ?> ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> </body> </html> <?php mysql_free_result($rsTestBOP); ?>