Thursday, June 30, 2005

How to force browsers to pop open a file save dialog?

Use the code below to force browsers to pop open a file save dialog when they access your page.

In JSP/Servlet

response.setHeader("Content-Disposition", "attachment;filename=myfile.txt");
response.setContentType("application/download");

3 comments:

~ se3loah ~ said...

good one ... thanx

ts said...

This is NOT correct. You must use application/octet-stream for unspecified binary data. Some browsers may try to display your data as text if you use application/download

Alex said...

IN PHP

header("Content-Disposition: attachment; filename=myfile.txt");
header("Content-Type: application/download");

A

Popular Posts (Last 30 days)

This is a personal blog and I do not speak for my employer.