让用户下载一个 XML 文件

2022-01-11 00:00:00 header php

我在 PHP 中准备了一个 XML 字符串,我想让用户下载一个 XML 文件中的字符串.

I have prepared an XML string in PHP and I would like to let the user download the string in an XML file.

是否可以在不将 xml 文件物理保存到服务器的情况下为用户提供下载(例如 text.xml)?

Is it possible to offer the user the download (e.g. text.xml) without physically saving the xml file to the server?

推荐答案

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

echo $xml_contents;

相关文章