Я хочу скачать Excel в папке ZIP. После этого он должен быть защищен паролем. Но это не работает.
public function download (){
$header = array('id');
require_once APPPATH."/third_party/PHPExcel.php";
$sheet = new PHPExcel();
$file = $this->appmodel->Data();
// echo "<pre>"; print_r($file); die;
$filename = $file->id;
$this->load->helper('date');
$date = date('Y-m-d');
//1st Sheet
$sheet->setActiveSheetIndex(0);
$activeSheet = $sheet->getActiveSheet();
$activeSheet->fromArray($header, null);
$objWriter = PHPExcel_IOFactory::createWriter($sheet, 'Excel2007');
// echo "<pre>"; print_r($objWriter); die;
$excel_file_tmp = tempnam("/tmp", 'your_prefix');
$objWriter->save($excel_file_tmp);
//zip
$zip_file_tmp = tempnam("/tmp", 'your_prefix');
$zip = new ZipArchive();
$zip->open($zip_file_tmp, ZipArchive::OVERWRITE);
$zip->addFile($excel_file_tmp, 'your_name.xlsx');
$zip->close();
//download
$password = "22";
$download_filename = 'your_name.zip';
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($zip_file_tmp));
header("Content-Disposition: attachment; filename=\"" . $download_filename . "\"");
@system("zip -P $password $excel_file_tmp $zip_file_tmp ");
readfile($zip_file_tmp);
// unlink($excel_file_tmp);
// unlink($zip_file_tmp);
@unlink($zip_file_tmp);
}