public function Exporter::save in Loft Data Grids 6.2
Same name and namespace in other branches
- 7.2 vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/Exporter.php \AKlump\LoftDataGrids\Exporter::save()
Save as a file to the server
Parameters
string $filename: The correct extension will be appended to this string
mixed $page_id: (Optional) Defaults to NULL. Set this to export a single page.
Overrides ExporterInterface::save
1 method overrides Exporter::save()
- XLSXExporter::save in vendor/
aklump/ loft_data_grids/ src/ AKlump/ LoftDataGrids/ XLSXExporter.php - Save as a file to the server
File
- vendor/
aklump/ loft_data_grids/ src/ AKlump/ LoftDataGrids/ Exporter.php, line 240
Class
- Exporter
- Class Exporter
Namespace
AKlump\LoftDataGridsCode
public function save($filename = '', $page_id = NULL) {
// Make sure we have rendered the data
if (empty($this->output)) {
$this
->compile($page_id);
}
// Assure the correct file extension
if ($filename) {
$this
->setFilename($filename);
}
$filename = $this
->getFilename();
// Make sure we don't timeout
$original = (int) ini_get('memory_limit');
$memory_limit = strlen($this->output);
//bytes
$memory_limit /= 1048576;
//convert to megabytes
$memory_limit *= 2;
//double the memory so we don't run out
if ($memory_limit > $original) {
$memory_limit *= 20;
//double the memory so we don't run out
$memory_limit = max($original, round($memory_limit)) . 'M';
ini_set('memory_limit', $memory_limit);
}
// Send download headers
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $this->filename . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . strlen($this->output));
// Send contents
print $this->output;
exit;
}