Im using a button to direct to a script which creates a text file:
<?php $handle = fopen("file.txt", "w"); fwrite($handle, "text1....."); fclose($handle); ?>
after that I want the web browser to propose to download or open this file how should I do? Thanks
On your computers desktop, right click on the item. Choose the 'Send to' option and then choose 'Compressed (zip) folder'. This will place your download in a zip folder. When attaching your downloadable item, choose the one that has been placed in the zip folder.
For force download, you have to set the header correctly. When you are setting the header for download the Zip file that time <coce>Content-type and Content-Disposition correctly. In Content-Disposition , add the attachment, it will suggest the browser to download the file instead of displaying it directly.
Show activity on this post. $filename = $_GET['movie']; //Get the filename if(is_file($filename)) { //If you want to read and output the contents do it here header('Content-disposition: attachment; filename='. $filename); } exit();
use readfile() and application/octet-stream
headers
<?php $handle = fopen("file.txt", "w"); fwrite($handle, "text1....."); fclose($handle); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename('file.txt')); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize('file.txt')); readfile('file.txt'); exit; ?>
$content = file_get_contents ($filename); header ('Content-Type: application/octet-stream'); echo $content;
Should work
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