public function YamlFormResultsExportController::downloadFile in YAML Form 8
Download generated CSV file.
Parameters
string $file_path: The paths the generate CSV file.
bool $download: Download the generated CSV file. Default to TRUE.
Return value
\Symfony\Component\HttpFoundation\Response A response object containing the CSV file.
2 calls to YamlFormResultsExportController::downloadFile()
- YamlFormResultsExportController::file in src/
Controller/ YamlFormResultsExportController.php - Returns form submission results as CSV file.
- YamlFormResultsExportController::index in src/
Controller/ YamlFormResultsExportController.php - Returns form submission as a CSV.
File
- src/
Controller/ YamlFormResultsExportController.php, line 183
Class
- YamlFormResultsExportController
- Controller routines for form submission export.
Namespace
Drupal\yamlform\ControllerCode
public function downloadFile($file_path, $download = TRUE) {
// Return the export file.
$contents = file_get_contents($file_path);
unlink($file_path);
$content_type = $this->mimeTypeGuesser
->guess($file_path);
if ($download) {
$headers = [
'Content-Length' => strlen($contents),
'Content-Type' => $content_type,
'Content-Disposition' => 'attachment; filename="' . basename($file_path) . '"',
];
}
else {
if ($content_type != 'text/html') {
$content_type = 'text/plain';
}
$headers = [
'Content-Length' => strlen($contents),
'Content-Type' => $content_type . '; charset=utf-8',
];
}
return new Response($contents, 200, $headers);
}