XML: stream output directly to a user's file
Posted: Sun Mar 15, 2009 7:27 am
Hi!
I am building an aplication that needs to send a XML file to the user. It should be sent as a stream because the file will be kind of big (larger than 20Mb) so it should not be stored in the server's memory before output.
I am using PHP 5.1.6 and the extension XMLWriter.
This extension alows me to do the following:
The function openURI() determines how the XML should be sent to the user. With the string 'php://output' it is in fact delivered as a stream, without great usage of the server's memory.
Now here's the thing:
Since the stream is delivered trough the browser and browsers are prepared to read the XML, instead of prompting the user with a file save window, the browse simply throws on the screen the content of the XML file that has to be saved.
Naturally, a 'connaisseur' knows what to do: calls for the page's source code and saves it as a XML.
However we all know that most users wont know that much, so I have to find a way to have the file saving window prompted to them. Confronted with 20 or 40 Mb of XML on the screen, they will simply say that the program crashed.
I think the solution probably lies on the use of a different string in the function openURI(), or in the use of some other funtion but I can't find anything about it on the internet. The XMLWriter extension it's kind of recent itself so it is very shortly documented on the official php.net site.
Can anyone give me a clue on this?
I am building an aplication that needs to send a XML file to the user. It should be sent as a stream because the file will be kind of big (larger than 20Mb) so it should not be stored in the server's memory before output.
I am using PHP 5.1.6 and the extension XMLWriter.
This extension alows me to do the following:
Code: Select all
<?php
$writer = new XMLWriter();
$writer->openURI('php://output');
...
?>
Now here's the thing:
Since the stream is delivered trough the browser and browsers are prepared to read the XML, instead of prompting the user with a file save window, the browse simply throws on the screen the content of the XML file that has to be saved.
Naturally, a 'connaisseur' knows what to do: calls for the page's source code and saves it as a XML.
However we all know that most users wont know that much, so I have to find a way to have the file saving window prompted to them. Confronted with 20 or 40 Mb of XML on the screen, they will simply say that the program crashed.
I think the solution probably lies on the use of a different string in the function openURI(), or in the use of some other funtion but I can't find anything about it on the internet. The XMLWriter extension it's kind of recent itself so it is very shortly documented on the official php.net site.
Can anyone give me a clue on this?