IT & Programming

Create downloadable file without saving

This php script generates a file to be downloaded without saving the file on server or disk. This script can create any type of file.

Script

$file_name='life.html';

$file_content='Life is beautiful';

header('Content-Description: File Transfer');

header('Content-Type: application/octet-stream');

header('Content-disposition: attachment; filename='.$file_name);

header('Content-Length: ' . strlen($file_content));

header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

header('Expires: 0');

header('Pragma: public');

Output

Leave A comment

Email address is optional and will not be published. Only add email address if you want a reply from blog author.
Please fill required fields marked with *