We help IT Professionals succeed at work.

Create DOM xml file & Open Save Prompt without writing the DOM to a file on the server?

namwenio asked
Last Modified: 2008-08-11
Inlcuded below is the code I am using.
Currently this will create my DOM XML file, save it to the server
Then prompt me to download the file.

I am trying to perform this operation without writing the XML file to the server.
Instead I would like to download it from a variable, so no file ever gets written to the server.

How can this be done?
    // force download 
    header("Content-type: application/force-download"); 
    header('Content-Disposition: inline; filename="' . $fileName . '"'); 
    header("Content-Transfer-Encoding: Binary"); 
    header("Content-length: ".filesize($fileName)); 
    header('Content-Type: application/octet-stream'); 
    header('Content-Disposition: attachment; filename="' . $fileName . '"'); 

Open in new window

Watch Question

"How can this be done?:"

It cannot be done in X-browser compatible sandbox mode.  If you are talking FF and Mozilla, the Gecko rendering follows the sandbox model -- no website should be allowed to change files directly on a users hard drive (you know the consequences).  IE uses active-X infection to get around this, therefore, in IE only, you can allow apps to write files to your hard drive (aka infect the drive if malicious).

Now if this is just you alone and for development purposes, you can give that website, in IE security, total control to do anything it wants (Internet options, security preferences, and assign the site max privs).

But if you are talking GENERAL website use, the correct logic is this -- a web page can write anything it wants to its own websites, or to other IP address sites with a TRUST relationship (also to subdomains which inherit the privs of the main domain).  So there is the XML file on the server.

How to get this to the local computer?  Aha, create a link to download the file -- which is exactly what you are getting.  There is another way around this, but you won't like it.  Go into windows explorer, and look at file, folder options, file types tab, and choose XML and set it to download rather than display in a browser.

Once you have gone through this exercise, you realize the sandbox models main principle -- ANY AND ALL FILE HANDLING TO THE LOCAL MACHINE IS UP TO THE USER TO DECIDE.  If the webpage can decide this without the user being involved, then all of our hard drives would have been wiped clean about 10 years ago.


I'm not saying that I want it to automatically download.

I'm trying to eliminate it writing the DOM XML document

I want it to basically stream the file from the server "container variable", then dispose of it.


After the file is downloaded remove the .xml file from the server.
This one is on us!
(Get your first solution completely free - no credit card required)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.