Php 从api下载数据时,如何使下载弹出窗口在chrome中工作?

Php 从api下载数据时,如何使下载弹出窗口在chrome中工作?,php,codeigniter,phpspreadsheet,Php,Codeigniter,Phpspreadsheet,我成功地将数据从API下载到excel,但在chrome中没有下载确认。这只是将其保存在供应商问题中。我想在chrome的下载中显示 public function download() { $host ="https://jsonplaceholder.typicode.com/posts"; $process = curl_init($host); curl_setopt($process, CURLOPT_TIMEOUT, 30)

我成功地将数据从API下载到excel,但在chrome中没有下载确认。这只是将其保存在供应商问题中。我想在chrome的下载中显示

public function download()
    {
        $host ="https://jsonplaceholder.typicode.com/posts";
        $process = curl_init($host); 

        curl_setopt($process, CURLOPT_TIMEOUT, 30);


        curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
        $return = curl_exec($process);
        curl_close($process);




        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
        $sheet->setCellValue('A1', 'Id');
        $sheet->setCellValue('B1', 'Name');
        $sheet->setCellValue('C1', 'Skills');
        $sheet->setCellValue('D1', 'Address');   
         $rows = 2;

         $results=json_decode($return);



        foreach ($results as $val){
            $sheet->setCellValue('A' . $rows, $val->id);
            $sheet->setCellValue('B' . $rows, $val->userId);
            $sheet->setCellValue('C' . $rows, $val->title);
            $sheet->setCellValue('D' . $rows, $val->body);
            $rows++;
        } 


        $writer=new Xlsx($spreadsheet);
        $writer->save('json.xlsx');



    }
它不是由PHP代码完成的,您需要的是浏览器功能 选中此链接可使Chrome显示下载内容


它是固定的。。。我只需要添加echo“”;