我正在尝试将网站中的文件保存到文件夹中,但是当我单击由我创建的按钮时,它将下载我要下载的文件到我想要的文件夹中,而不是下载到文件夹=>希望这是有道理的:)
class Export extends CI_Controller{
public function excel(){
$this->load->model('AfterClassFeedback_model');
// get the information from the table to put on the page
$feedback = new AfterClassFeedback_model;
$feedback->table = 'afterclassfeedback';
$feedback->primary_key = 'id';
$data['list'] = $feedback->read();
require(APPPATH.'third_party/PHPExcel-1.8/Classes/PHPExcel.php');
require(APPPATH.'third_party/PHPExcel-1.8/Classes/PHPExcel/Writer/Excel2007.php');
$objPHPExcel = new PHPExcel();
// you can set some properties here
//$objPHPExcel->getProperties()->setCreator("");
$objPHPExcel->setActiveSheetIndex(0);
// setting the values in the active sheet
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'ID');
$objPHPExcel->getActiveSheet()->SetCellValue('B1', 'Date Added');
$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Question 1');
$objPHPExcel->getActiveSheet()->SetCellValue('D1', 'Question 2');
$objPHPExcel->getActiveSheet()->SetCellValue('E1', 'Question 3');
$objPHPExcel->getActiveSheet()->SetCellValue('F1', 'Question 4');
$objPHPExcel->getActiveSheet()->SetCellValue('G1', 'Question 5');
$row = 2;
// echo "<pre>";
// print_r($data['list']);
// echo "</pre>";
foreach($data['list'] as $key => $value){
$objPHPExcel->getActiveSheet()->SetCellValue('A'.$row,$value->id);
$objPHPExcel->getActiveSheet()->SetCellValue('B'.$row,$value->date_added);
$objPHPExcel->getActiveSheet()->SetCellValue('C'.$row,$value->question1);
$objPHPExcel->getActiveSheet()->SetCellValue('D'.$row,$value->question2);
$objPHPExcel->getActiveSheet()->SetCellValue('E'.$row,$value->question3);
$objPHPExcel->getActiveSheet()->SetCellValue('F'.$row,$value->question4);
$objPHPExcel->getActiveSheet()->SetCellValue('G'.$row,$value->question5);
$row++;
}
$path = base_url();
$fullPath = 'uploads';
$filename = "FEED_BACK_REPORT".date("ymd")."_TIME_".date("H:i:s").'.xlsx';
$objPHPExcel->getActiveSheet()->SetTitle("After_Class_Feedback_Report");
$myLocation = $path.$fullPath;
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/save");
header('Content-Disposition: attachment;filename='.$filename);
header('Cache-Control: max-age=0');
$writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$writer->save('php://output', 'w');
exit;
}
答案 0 :(得分:-1)
这是不可能的,您需要在浏览器中设置下载文件夹