codeigniter php Excel下载文件在2个地方,第一个在htdocs和下载文件夹,如何阻止文件下载htdocs或在服务器上?

nc1teljy  于 2022-12-07  发布在  PHP
关注(0)|答案(1)|浏览(261)
public function genrate_business_XLS_file($export_data) { 
            // create file name
            $fileName = 'Business-report-'.date("d-M-Y").'-'.time().'.xlsx';  
            // load excel library
            $this->load->library('excel');
            $objPHPExcel = new PHPExcel();
            $objPHPExcel->setActiveSheetIndex(0);
            // set Header
            $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'USER ID');
            $objPHPExcel->getActiveSheet()->SetCellValue('B1', 'BUSINESS NAME');
            $objPHPExcel->getActiveSheet()->SetCellValue('C1', 'PHONE');
            $objPHPExcel->getActiveSheet()->SetCellValue('D1', 'EMAIL');   
            // set Row
            $rowCount = 2;
            foreach ($export_data as $val) 
            {

            //echo"<pre>";print_r($val);die;
                $action = '';
                if($val['b_status']==0){
                    $action = 'Rejected Application';
                } else if($val['b_status']==1){
                    $action = 'Approved Application';
                }else if($val['b_status']==2){
                    $action = 'New Application';
                }
                $objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowCount, $val['b_id']);
                $objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowCount, $val['b_name']?$val['b_name']:'N/A');
                $objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowCount, $val['b_phone']?$val['b_phone']:'N/A');
                $objPHPExcel->getActiveSheet()->SetCellValue('D' . $rowCount, $val['b_email']?$val['b_email']:'N/A');
                $rowCount++;
            }

            $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
            $objWriter->save($fileName);
            // download file
            header("Content-Description: File Transfer");
            header("Content-Type: application/vnd.ms-excel"); 
            redirect(site_url().$fileName);
                
    }`
olmpazwi

olmpazwi1#

将文件保存到不在服务器上的php输出

header("Content-Type: application/vnd.ms-excel"); 
header('Content-Disposition: attachment;filename="'.$fileName.'"');
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save('php://output');

相关问题