PHP generate file for download then redirect

前端 未结 11 2951
春和景丽
春和景丽 2020-11-22 09:08

I have a PHP app that creates a CSV file which is forced to download using headers. Here\'s the relevant part of the code:

header(\'Content-Type: applicatio         


        
11条回答
  •  猫巷女王i
    2020-11-22 09:30

    I don't think this can be done - although I am not 100% sure.

    The common thing (e.g. in popular download sites) is the reverse: first you go to the after page and then the download starts.

    So redirect your users to the final page that (among other things) says:

    Your download should start automatically. If not click [a href="create_csv.php"]here[/a].

    As about initiating the download (e.g. automatically calling create_csv.php) you have many options:

    • HTML: [meta http-equiv="refresh" content="5;url=http://site/create_csv.php"]
    • Javascript: location.href = 'http://site/create_csv.php';
    • iframe: [iframe src="create_csv.php"][/iframe]

提交回复
热议问题