I'm trying to write a script that will create a file on the server then use header()
to redirect the user to that file. Then, after about 10 seconds I want to delete the file. I've tried this:
header('Location: '.$url);
flush();
sleep(10);
unlink($url);
But the browser just waits for the script to complete then gets redirected, but the file hes been deleted by that time. Is there someway to tell the browser "end of file", then keep computing? Or maybe have PHP start another script, but not wait for that script to finish?
You might be better off having the PHP page serve the file. No need to create a temporary file in this case and delete it, just send out the data you intended to write to the temporary file. You will need to set the headers correctly so the browser can identify the type of file you are sending. i.e. Content-Type: text/xml; for xml or image/jpeg for jpg's.
This method also handles slow clients that take longer to download the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With