我的php代码如下,它生成的源代码为我提供了我想要保存为xml文件的数据。我怎么能这样做?
ini_set ("display_errors", "1");
error_reporting(E_ALL);
session_start();
include_once('function.php');
$select_query = build_select_query("xml","cust_id",$_SESSION['cust_id']);
$query = mysqli_query($link,$select_query);
$num_rows = mysqli_num_rows($query);
if($num_rows > 0){
while($row = mysqli_fetch_assoc($query)){
?>
<all>
<Phonebooks>
<book id='{$row['bookid']}' Bookid='{$row['bookid']}' speedid='{$row['speedid']}' accountid='{$row['accountid']}'
GroupName='{$row['groupid']}' FirstName='{$row['firstname']}' Username='{$row['username']}'
MobileNum='{$row['mobilenum']}' OfficeNum='{$row['officenum']}' OtherNum='{$row['othernum']}' NewVer='{$row['newver']}' ISUseBLF='{$row['isuseblf']}'
LastName='{$row['lastname']}' GroupNameTwo='{$row['groupnametwo']}' />
</Phonebooks>
</all>
<?php
}
}
?>
答案 0 :(得分:1)
请尽量让您的问题在将来尽可能明确。这样你就可以马上得到正确的答案。
make_my_xml.php - 当您在浏览器中将其作为stuff.xml加载时,此文件会打印xml并保存/下载
<?php
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
// change this line to change the filename it saves as
header('Content-Disposition: attachment; filename=stuff.xml');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
// your code goes here
ini_set ("display_errors", "1");
error_reporting(E_ALL);
session_start();
include_once('function.php');
$select_query = build_select_query("xml","cust_id",$_SESSION['cust_id']);
$query = mysqli_query($link,$select_query);
$num_rows = mysqli_num_rows($query);
if($num_rows > 0){
while($row = mysqli_fetch_assoc($query)){
?>
<all>
<Phonebooks>
<book id='{$row['bookid']}' Bookid='{$row['bookid']}' speedid='{$row['speedid']}' accountid='{$row['accountid']}'
GroupName='{$row['groupid']}' FirstName='{$row['firstname']}' Username='{$row['username']}'
MobileNum='{$row['mobilenum']}' OfficeNum='{$row['officenum']}' OtherNum='{$row['othernum']}' NewVer='{$row['newver']}' ISUseBLF='{$row['isuseblf']}'
LastName='{$row['lastname']}' GroupNameTwo='{$row['groupnametwo']}' />
</Phonebooks>
</all>
<?php
}
}
?>
如果您想通过单击按钮来执行此操作...我想,只需创建一个普通按钮或链接,转到包含创建/保存xml文件的代码的页面。我错过了什么吗?
other_file.php - 链接到网页的两种不同方式
<a href="make_my_xml.php" target="_blank">Click here to download an xml file!</a>
<form method="link" action="make_my_xml.php"><input type="submit" value="Click to Download XML File"></form>
请告诉我这个解决方案是否适合你......