开发者

PHP call function after header for file download is called

I have a function creating a file for download like so:

header("Content-type: application/octet-stream");
header("Content-disposition: filename=file.csv");
print 'hello hello';
exit;

$this->nextFuntion();

I need the "nextFunction" to be called after the save dialogue pops up, I've seen various methods around here but they all have to do with header('location:') feature. Bas开发者_JS百科icly the page where the function is called contains the data that goes inside the file. the "nextFunction" will erase the data form the page and return a message etc.

But the best I can do is get the download to work and no function.


Split this into two scripts. The first will call the function, and then redirect to the second (via a META refresh or the like) which will be responsible for sending the file to be downloaded.


Are you sure you always want to erase the file immediately after it's downloaded? If the user wants to download it again and it's unavailable, this functionality could annoy them. I'd recommend setting up a cron job to delete all files that are older than a certain time.


I think your issue is more to do with nextFunction() as PHP should allow you to call functions even after headers are set.

Try it with a test function that just logs to a file or my personal favorite exec("echo 'HAY HAY' | wall ");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜