php - 如何将标头添加到用 PHP 创建的 XML 文件
问题描述
我有一个代码,它从数据库中获取数据并创建一个 XML 文件。我需要将此类标头添加到 xml 文件中。需要的标题:
header("Content-type: text/xml");
header('Content-Desposition: attachment; filename="products.xml"');
原始的php代码:
<?php
include('dbconnect.php');
function loadXML(){
global $dbh;
$result = $dbh->query("SELECT * FROM stock_infos;");
$name = strftime('products.xml');
$xml = new SimpleXMLElement('<nuts/>');
while($row = $result->fetch(PDO::FETCH_ASSOC)){
$nut = $xml->addChild('nut');
$nut->addChild('code',$row['code_product']);
$nut->addChild('name_product',$row['name_product']);
$nut->addChild('in_stock',$row['in_stock']);
$nut->addChild('date_stock',$row['date_stock']);
}
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
$dom->save(dirname(__FILE__).'/'.$name);
}
loadXML();
?>
代码最终应该是什么样子,以便生成带有所需标头的 XML 文件?
谢谢!
解决方案
推荐阅读
- facebook-graph-api - Facebook 图形 api groups_access_member_info 权限
- deep-learning - 获取 ONNX 模式的中间层输出
- api - 如何解决vue中axios发布请求中的404错误?
- python - 如何在循环中更改实例属性的值
- logistic-regression - 如何解释逻辑回归的结果?
- r - 使用 r 有条件地处理对另一列的重复项
- swift - 如何在 coreML Swift 中将图像列表作为 MLMultiArray 传递?
- mule - 在 mule 3 的日期时间字段中添加 2hr
- php - 数组合并返回键
- html - 如何增加一侧div的高度?