xyc
2024-05-17 6b24f642b01cf3cd1be0d5833273fa2867d389e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/*
 * filesave.php
 * To be used with ext-server_opensave.js for SVG-edit
 *
 * Licensed under the Apache License, Version 2
 *
 * Copyright(c) 2010 Alexis Deveria
 *
 */
 
if(!isset($_POST['output_svg']) && !isset($_POST['output_png'])) {
  die('post fail');
}
 
$file = '';
 
$suffix = isset($_POST['output_svg'])?'.svg':'.png';
 
if(isset($_POST['filename']) && strlen($_POST['filename']) > 0) {
  $file = $_POST['filename'] . $suffix;
} else {
  $file = 'image' . $suffix;
}
 
if($suffix == '.svg') {
  $mime = 'image/svg+xml';
  $contents = rawurldecode($_POST['output_svg']);
} else {
  $mime = 'image/png';
  $contents = $_POST['output_png'];
  $pos = (strpos($contents, 'base64,') + 7);
  $contents = base64_decode(substr($contents, $pos));
}
 
 header("Cache-Control: public");
 header("Content-Description: File Transfer");
 header("Content-Disposition: attachment; filename=" . $file);
 header("Content-Type: " .  $mime);
 header("Content-Transfer-Encoding: binary");
 
 echo $contents;
 
?>