这段代码可以正常工作。
<?php
$file = "forumsmap.svg";
header('Content-type: image/svg+xml');
header("Content-Disposition: attachment; filename=$file");
echo('<svg width="362" height="256" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"><!-- Created with SVG-edit - https://github.com/SVG-Edit/svgedit--><g><title>Layer 1</title><ellipse ry="23" rx="75" id="svg_7" cy="123" cx="191.5" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="null" stroke="#000000" fill="#ffffff"/></g></svg>');
?>但是当我使用POST数据修改代码时
<?php
$data = $_POST['content'];
$file = "forumsmap.svg";
header('Content-type: image/svg+xml');
header("Content-Disposition: attachment; filename=$file");
echo $data;
?>然后打开SVG文件,收到以下错误消息:
此页包含以下错误:
第1栏第2行错误:文档末尾的额外内容
下面是第一个错误之前的页面渲染。
请告诉我怎么修理它。谢谢
发布于 2016-05-31 18:37:35
仔细看看$data变量。它可能在末尾包含一个换行符,对于您指定的内容类型来说,它是无效的。
<?php
$data = $_POST['content'];
$file = "forumsmap.svg";
header('Content-type: image/svg+xml');
header("Content-Disposition: attachment; filename=$file");
echo $data;
print_r($data);这应该能让你更好地了解正在发生的事情。
服务器错误,或修改内容的其他组件。
最终,您所描述的问题有很多潜在的原因,从服务器错误将HTML内容转储到$_POST['content']变量,到数据没有正确地为image/svg+xml编码
https://stackoverflow.com/questions/37552900
复制相似问题