PHP generate file for download then redirect

前端 未结 11 2690
春和景丽
春和景丽 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条回答
  •  醉酒成梦
    2020-11-22 09:22

    Hmmmm...

    Put the code below in the main javascript of the site.

     if (window.location.pathname == '/url_of_redirect/') {
            window.open(location.protocol + '//' + location.hostname + '/url_of_download.zip', '_parent');
        }
    

    Explaining: It does the normal redirect with php to some url you will difine and in javascipt it says: If the pathname is the same as the path that redirect made '/url_of_redirect/' then it opens the url on a new page, generating the downlod.

提交回复
热议问题