Download xml file

Hello,
First, I am very new to php. Bloody Beginner.
My problem is, that i want the user to be able to download a generated
xml file. I have working code which savies it to a file and sends it:

$fp = fopen($xml_file,'a');
fwrite($fp, $result[..]);
fclose($fp);

Is it possible to avoid writing the file? the $result contains all
data. how can I do this? Can someone help me with the command to send
data back to the user? I found similar code in
http://groups.google.de/group/comp.lang.php/browse_thread/th read/ecdc3bb9845ea721/96cd1d6bc5fbeb08?hl=de&lnk=gst&q=downl oad#96cd1d6bc5fbeb08
Should i provide some information about the xml mine type?

Thanks for help!
c
chrissionair [ Mi, 16 Januar 2008 12:10 ] [ ID #1909693 ]

Re: Download xml file

C. Müller wrote:
> Hello,
> First, I am very new to php. Bloody Beginner.
> My problem is, that i want the user to be able to download a generated
> xml file. I have working code which savies it to a file and sends it:
>
> $fp = fopen($xml_file,'a');
> fwrite($fp, $result[..]);
> fclose($fp);
>
> Is it possible to avoid writing the file? the $result contains all
> data. how can I do this? Can someone help me with the command to send
> data back to the user? I found similar code in
> http://groups.google.de/group/comp.lang.php/browse_thread/th read/ecdc3bb9845ea721/96cd1d6bc5fbeb08?hl=de&lnk=gst&q=downl oad#96cd1d6bc5fbeb08
> Should i provide some information about the xml mine type?
>
> Thanks for help!
> c
>

If this is the only thing your function does, you can just set the
content type and disposition and send the file.

The problem comes if your script also outputs something else - i.e.
html, images, etc. Each of those types has its own content type and
disposition, and a document can't have more than one.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Mi, 16 Januar 2008 13:20 ] [ ID #1909699 ]

Re: Download xml file

C. Müller wrote:

> Can someone help me with the command to send data back to the user?

<?php
header("Content-Type: application/xml");
print $result[..];
?>


--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 17 days, 5 min.]

Gnocchi all'Amatriciana al Forno
http://tobyinkster.co.uk/blog/2008/01/15/gnocchi-allamatrici ana/
Toby A Inkster [ Mi, 16 Januar 2008 13:52 ] [ ID #1909702 ]

Re: Download xml file

Hello,

Thank you Toby, it works! Wow, that's short.
With your help i found this on the net:

header("Content-Type: text/xml; charset=utf-8");
$xmldef = '<?xml version="1.0" encoding="UTF-8"?>
';
echo $xmldef;
echo $result[..]

Which works also. Thanks,
C.
chrissionair [ Mi, 16 Januar 2008 15:53 ] [ ID #1909717 ]
PHP » comp.lang.php » Download xml file

Vorheriges Thema: Sorting an Array
Nächstes Thema: cannot do system() exec() or anything +cannot unlink