简体   繁体   中英

File download using php include null values

I have default csv template. I need to show this template when user click on a specific button.

The code is here

    $filePath = $_SERVER['DOCUMENT_ROOT']."/content/formatted_blank.csv";
    $csvfile  = file_get_contents($filePath);
    $filename = "formatted_blank.csv";
    echo $csvfile;
    header("Content-type: application/csv");
    header("Content-Disposition: attachment; filename=\"".$filename."\"");
    die();

The code is working fine. But the output file is not matching my default template. In default template i wrote header in 1 row But download file showing in 7th row. There is white space rows coming.

if any one know about this please help me.

You can not use header functions after echo . Make the oposite

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM