0

I have problem with mozilla firefox in this case. I am generating file on the fly and then trying to download the file and then delete it from the server. Problem is, Firefox says the file doesnt exists, even though I can see it is generated on the server. Chrome and Opera works perfectly.

firefox version: 58.0.2

Any ides what has to be tuned for firefox ?

header('location: /path/'.$name.'.pptx');
header('Content-Disposition: attachment; filename="' .basename($name).'.pptx"');

ob_start();
flush();
sleep(5);
unlink($name.'.pptx');
marhyno
  • 677
  • 1
  • 8
  • 20
  • https://stackoverflow.com/questions/2641667/deleting-a-file-after-user-download-it – iwex Mar 13 '18 at 10:04
  • This is not my problem. My problem is that mozilla cannot find the file. 404 error is thrown. Unlink works good. – marhyno Mar 13 '18 at 10:07
  • 1
    Your `sleep(5)` isn't good practice – iwex Mar 13 '18 at 10:08
  • 1
    And also why are you changing `Location`? – iwex Mar 13 '18 at 10:12
  • So what should I change ? Add more, change for something else ? As I said, in Chrome and Opera its works good, code generates the file user downloads file and 5 seconds after flush file is deleted. Why it should not work in mozilla ? – marhyno Mar 13 '18 at 10:12
  • Try to remove the first header with the change of location. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location – KIKO Software Mar 13 '18 at 10:19
  • @KIKOSoftware thanks for the suggestion I tried it, at least something happened that firefox tried to download the file but File is corrupt and there is only output from the php script, I also tried adding headers that I want to download content-type download / force-download / octet-stream and nothing works also now in Chrome and Opera. So back to the beginning, why is mozilla telling me it cannot find the file. – marhyno Mar 13 '18 at 11:15
  • From the code you posted that would be exactly what Firefox, or any other browser, should do. Somehow I think you're not letting us see the whole picture here. Anyway, it seems obvious to me that you're using code you don't understand. You're not trying to understand it either. There's enough documentation out there, read it and learn. If you, after that, find some inconsistency, for which you cannot find any documentation or solution, then it's time to ask a question here. See: https://stackoverflow.com/help/how-to-ask – KIKO Software Mar 13 '18 at 12:33

1 Answers1

2

First of all, just for sanity, please use Location instead of location.

Also, as per my understanding, once you send the Location header, the browser does a redirect to the specified URL. When the browser has redirected to a different page, I feel all the headers post Location shall be rendered useless. The URL from which you are downloading should send the Content-Disposition header. Also, I would suggest adding the headers Content-Type and Content-Length on the download URL.

Shammi Shailaj
  • 445
  • 5
  • 14