View Full Version : Raising "save as" dialog

06-02-2005, 07:23 PM

I have a web project that tracks warehouse inventory. THey want to be able to print barcodes for scanning. I wanted to originally generate the file and write it to the client's HD and if possible raise the print dialog automatically to print them. They do high volume so I need this to be as streamline as possible.

Before anyone chimes in with "Malicious malware", save your breath please.

I found this post on a forum :

There are valid and legitimate reasons for wanting to write to the visitors harddrive. However, the only secure and acceptable method of doing so is to use server-side code to send an HTTP attachment to the browser and let the browser raise the Save As dialog box to ask the visitor where they would like to write the file. At that point, of course, the visitor has the right to refuse the file altogether.

I would be fine with this. If I can take a file, generate it and have the save as dialog pop up automatically, giving them the ability to save it to their HD that would be fine. How do I do this? At this point I can generate a text or html file for this purpose. But I do not know how to send an HTTP attachment to the browser and let the browser raise the Save As dialog box. I am using php FYI.

If you have a better approach that does not involve a bunch of extra steps for the user, I am all ears. If I can not do this, then I will be forced to write the file on the server, then have a program running on the client's machine checking for files on the server. I would rather not have to do this. Again they want this functionality and it is an internal application so they are aware of the security issues.

Thank you for any help with this.

06-02-2005, 07:45 PM
You have to change the context headers... using PHP. This is not a JS question. But i will answer it in ASP because that is what i know :) I know it is easy to change to PHP though

Response.ContentType = "application/x-download"
Response.AddHeader "content-disposition","attachment; filename=" & fileName & ".xls"

06-02-2005, 07:50 PM
Thank you for your reply. Since I do not know asp and I am trying something I have never done before, could you give me an idea of what I could type into google to find the php version of what you gave me?

Thanks alot

Harry Armadillo
06-02-2005, 07:56 PM

06-02-2005, 07:57 PM
Thanks :D

06-02-2005, 09:12 PM
Topic continued in PHP category: http://www.codingforums.com/showthread.php?t=60315 Closing this one.