I want to rename file when user downloads it.
Right now, I'm sending content-disposition and content-length headers and then send file to user with fpassthru PHP function.
But there is 3 problems with this method:
Is there any nicer way to rename files on download?
Since the question was asked, some time has gone by and html5
gave us a different approach to this:
<a href="someWeiredFileName.rar" download="coolFilename.rar">Download</a>
The attribute
download (learn more) defines the default filename
for storing the file on the clients computer (he'll still be able to change it!).
Note: this won't affect anything on your server.
<?php
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>
Pseudo code
while(1) {
Echo "..."; //<-- send this to the client
if (connection_status()!=0){
die;
}
}
You can stop the PHP script if a user cancels the browser by using connection_status()
HTTP can not reconnect a closed connection. FTP can!
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