开发者

How can I export to an XML file instead of printing it on screen?

How can I edit the code I use below to save the generated file instead of printing it on the screen ?

<?php
header("Content-type: text/xml");

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");

$query = "";
$resultID = mysql_query($query, $linkID) or die("Data not found.");

$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<products>\n";

for($x = 0 ; $x < mysql_num_row开发者_Python百科s($resultID) ; $x++){
    $row = mysql_fetch_assoc($resultID);

    $xml_output .= "\t<product>\n";
.
.
.
    $xml_output .= "\t</product>\n";
}

$xml_output .= "</products>";

echo $xml_output;
?> 


You would use the "Content-Disposition" header to provide a recommended filename and force the web browser to show the save dialog.

For example:

<?php
header('Content-type: text/xml');
header('Content-Disposition: attachment; filename="downloaded.xml"');

// ...your other code
?>

This isn't guaranteed to work on all server setups and all browsers so you will find further information on the PHP header function page: http://php.net/manual/en/function.header.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜