48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
//used to export content to download
|
|
namespace Hura8\System;
|
|
|
|
|
|
class Export
|
|
{
|
|
public function export($content, $file_name, $type)
|
|
{
|
|
if($type=='xls' || $type=='xlsx') {
|
|
$this->setHeaderXLS($file_name);
|
|
}
|
|
else if($type=='doc') {
|
|
$this->setHeaderDoc($file_name);
|
|
}
|
|
else if($type=='csv') {
|
|
$this->setHeaderCSV($file_name);
|
|
}
|
|
|
|
echo $content;
|
|
}
|
|
|
|
// method for Excel file
|
|
protected function setHeaderXLS($file_name)
|
|
{
|
|
header("Content-type: application/ms-excel");
|
|
header("Content-Disposition: attachment; filename=$file_name");
|
|
header("Pragma: no-cache");
|
|
header("Expires: 0");
|
|
}
|
|
|
|
// method for Doc file
|
|
protected function setHeaderDoc($file_name)
|
|
{
|
|
header("Content-type: application/x-ms-download");
|
|
header("Content-Disposition: attachment; filename=$file_name");
|
|
header('Cache-Control: public');
|
|
}
|
|
|
|
// method for CSV file
|
|
protected function setHeaderCSV($file_name)
|
|
{
|
|
header("Content-type: application/csv");
|
|
header("Content-Disposition: inline; filename=$file_name");
|
|
}
|
|
}
|