Я пытаюсь записать файл в браузер для загрузки, и у меня есть следующие заголовки:
Код: Выделить всё
// Create a file pointer connected to the file path
$output = fopen($file_path, 'w');
if ($output === false) {
die("Unable to open file for writing: " . $file_path);
}
// Output the column headings if there are any results
if (count($data) > 0) {
fputcsv($output, array_keys($data[0]));
}
// Output the data
foreach ($data as $row) {
fputcsv($output, $row);
}
// Close the file pointer
fclose($output);
// Close the database connection
$mysqli->close();
// Clear the output buffer
while (ob_get_level()) {
ob_end_clean();
}
if (file_exists($file_path)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file_path) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file_path));
readfile($file_path);
}
Подробнее здесь: https://stackoverflow.com/questions/785 ... v-download
Мобильная версия