I’m looking for php code that changes file name -adds current date, and starts download the file with delay. If download will not start there is an option to download the file with added date by clicking the link.
Something like this:
Your download will begin in a few moments… If nothing happens, click <a href="">here</a>.
I found only this:
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('plik.pdf');
https://stackoverflow.com/a/6694505
Please help me.
You will need two parts to do this effectively… In your displayed PHP file (let’s call it
download.php), you’ll need to kick off a Javascript function that counts down for your customer to zero. When it reaches zero, it simply redirects to the real download location (let’s call itrealdl.php). This file would actually grab the file content and send it to the user when either redirected or clicked.Here are some elements you would need in
download.php:Then, all you would need in
realdl.phpis the following:Of course, you need to provide the methods to get the file contents (either just read from disk or possibly database) as well as to determine the file name. To use time as a filename format, see https://www.php.net/manual/en/function.strftime.php for the
strftimefunction.Depending on how the file is stored, you can be more effective, using
fpassthrufor local files, as an example. You also may want to send theContent-Lengthheader if you can determine the file size prior to downloading (i.e. it is static content you are sending).