[英]How do I prompt the user to download a PHP-generated .CSV file, and how should I handle deleting it?
[英]How do I create an XML file with php and have it prompt to download?
我正在使用domdocument创建一个xml文件:
$dom = new DOMDocument('1.0', 'iso-8859-1');
echo $dom->saveXML();
当我单击此文件的链接时,它只是将其显示为xml文件。 我如何提示下载呢? 此外,如何提示我将其下载为“ backup_11_7_09.xml”(插入今天的日期并将其作为xml),而不是php文件的真实名称“ backup.php”
在回显之前,将Content-Disposition
标头设置为附件:
<? header('Content-Disposition: attachment;filename=myfile.xml'); ?>
当然,您可以使用strftime()
格式化myfile.xml
以获得文件名中的格式化日期:
<?
$name = strftime('backup_%m_%d_%Y.xml');
header('Content-Disposition: attachment;filename=' . $name);
header('Content-Type: text/xml');
echo $dom->saveXML();
?>
<?php
// We'll be outputting a PDF
header('Content-type: text/xml');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="my xml file.xml"');
// The PDF source is in original.pdf
readfile('saved.xml'); // or otherwise print your xml to the response stream
?>
使用content-disposition标头。
这应该工作:
header('Content-Disposition: attachment; filename=dom.xml');
header("Content-Type: application/force-download");
header('Pragma: private');
header('Cache-control: private, must-revalidate');
$dom = new DOMDocument('1.0', 'iso-8859-1');
echo $dom->saveXML();
如果您使用会话,请使用以下设置来防止IE6问题:
session_cache_limiter("must-revalidate");
session_start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.