我正在制作一个使用 SVG、d3.js 和 JQuery 的数据可视化工具。我目前正在制作将导出(和下载)为 SVG 文件的功能:
// Code on main page
var svg = $("#svg-wrap").html();
var win = window.open("export.php?svg=" + svg, '_blank'); // _blank means export.php opens in a new tab
win.focus;
// Code in export.php
<?php
ob_start();
header("Content-Type: application/octet-stream");
header("Content-disposition: attachment; filename=data.svg");
$svg = $_GET["svg"];
echo stripslashes($svg);
?>
但这不起作用,因为尽管传递了一些 SVG,但完整的代码对于查询字符串来说太长了(或者看起来如此)。
有什么办法可以解决这个问题吗?我可以使用压缩,但这只会将其缩小到一个极限,而且我认为它可能仍然太长 - SVG 代码可能有数百行 :( 。