0

In my project I am creating a excel file and providing user to downlod it by

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

code. I am triggering file generating code by $(location).attr('href','###'); code in JS so it gives call to file exporting page and after generating file download window appears. For showing work in progress I have displayed loader window when export button clicked before calling $(location) and for closing this window I have used Jquery cookie library (To actualy check when file generation is completed and download window appears) For this I have referred

Detect when browser receives file download

Url this technique solves my problem and I can able to check when progress is completed and removed loader window.

Now I also want to show the progress of file completion. ie. my excel file generating with some 500 rows. So it takes time for generation, I have tried to write progress in cookie like 25% after 100 rows written, 50% after 200 rows written and tried to check that cookie value in JS code

fileProgress = window.setInterval(function () {
    var cookieValue = $.cookie('fileProgressToken');
    alert(cookieValue)
}, 1000);

but it doesn't work, I found that php set cookie value after page progress completes (ie. when all file generation process completes) and set value as 100 and I am not able to check the progress after 1 second.

What shall I do to achieve this, Does it possible or any simple alternative way

Community
  • 1
  • 1
mujaffars
  • 1,395
  • 2
  • 15
  • 35
  • Headers are sent once before any data is transferred, once data is being transferred the headers have gone and cookies can no longer be set unless you use an ajax call and the cookie is updated by JS rather than php – Anigel Jul 15 '13 at 09:45
  • Short answer - you can't. You need to send updates and your idea to have headers to write to a cookie won't work because PHP doesn't reply to a HTTP request in chunks which you can access as they come in (nor does any other language for that matter). – N.B. Jul 15 '13 at 09:47
  • you need the report to be generated asynchronously and update the progress in a db table or smthing rather than cookies – Daniel W. Jul 15 '13 at 09:53
  • Thank you guys, I will try db table option – mujaffars Jul 15 '13 at 12:49

0 Answers0