小编Ale*_*Exc的帖子

使用PHP清理SVG

我正在使用d3.js创建图表作为SVG.这些图表是根据经过身份验证的用户的选择动态生成的.生成这些图表后,用户可以选择将生成的SVG下载为PNG或PDF.

目前的工作流程如下:

// JAVASC
// get the element containing generated SVG
var svg = document.getElementById("chart-container");

// Extract the data as SVG text string
var svg_xml = (new XMLSerializer).serializeToString(svg);

// Submit the <FORM> to the server.
var form = document.getElementById("svgform");
form['output_format'].value = output_format;  // can be either "pdf" or "png"
form['data'].value = svg_xml ;
form.submit();
Run Code Online (Sandbox Code Playgroud)

FORM元素是一个隐藏的表单,用于POST数据:

<form id="svgform" method="post" action="conversion.php">
  <input type="hidden" id="output_format" name="output_format" value="">
  <input type="hidden" id="data" name="data" value="">
</form>
Run Code Online (Sandbox Code Playgroud)

PHP文件将提供的SVG数据保存为临时文件:

// check for valid session, etc - omitted for …
Run Code Online (Sandbox Code Playgroud)

php svg sanitization

8
推荐指数
1
解决办法
2548
查看次数

标签 统计

php ×1

sanitization ×1

svg ×1