我正在尝试使用 Laravel 生成 XML 文件。从控制器开始,我在控制器中生成需要在 XML 文件上使用的数据。我使用刀片模板生成 XML 文件,但无法自动保存或下载该文件
$xml_datos = [];
$total = 0;
.
.
.
$output = View::make('site.contabilidad.adeudosXML')->with(compact('xml_datos', 'total'))->render();
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n <Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:pain.008.001.02\">" .$output;
return $xml;
Run Code Online (Sandbox Code Playgroud)
我需要下载文件,而不是显示文件。我尝试过使用存储和文件系统类,但它们似乎都不起作用
您可以创建这样的响应:
public function saveXML()
{
$output = View::make('site.contabilidad.adeudosXML')->with(compact('xml_datos', 'total'))->render();
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n <Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:pain.008.001.02\">" .$output;
$response = Response::create($xml, 200);
$response->header('Content-Type', 'text/xml');
$response->header('Cache-Control', 'public');
$response->header('Content-Description', 'File Transfer');
$response->header('Content-Disposition', 'attachment; filename=' . yourFileNameHere . '');
$response->header('Content-Transfer-Encoding', 'binary');
return $response;
}
Run Code Online (Sandbox Code Playgroud)
另外,我强烈建议您使用PHP 函数来操作 XML。
| 归档时间: |
|
| 查看次数: |
14890 次 |
| 最近记录: |