home | contact us
» php » PHP Force Download with Custom Filename

BLOG CATEGORY: php


If you want to serve up text files for download (perhaps product feeds etc) then you might like this little snippet.

Not only will it force the file to be downloaded but it allows you to specify a custom filename that it should be saved as.

if(isset($_GET['download_file'])){
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=Export.txt");
    readfile('Export.txt');
    die;
}

Click Here to Contact Us about PHP Force Download with Custom Filename
 

Comments

No Comments

Leave a Reply

rss icon