xyc
2025-02-21 664db98c9e8595ce4dd636a27f480e3a08b81ff5
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<?php
/*
 * fileopen.php
 * To be used with ext-server_opensave.js for SVG-edit
 *
 * Licensed under the MIT License
 *
 * Copyright(c) 2010 Alexis Deveria
 *
 */
  // Very minimal PHP file, all we do is Base64 encode the uploaded file and
  // return it to the editor
 
  if (!isset($_REQUEST['type'])) {
    echo 'No type given';
    exit;
  }
  $type = $_REQUEST['type'];
  if (!in_array($type, array('load_svg', 'import_svg', 'import_img'))) {
    echo 'Not a recognized type';
    exit;
  }
 
  require('allowedMimeTypes.php');
 
  $file = $_FILES['svg_file']['tmp_name'];
 
  $output = file_get_contents($file);
 
  $prefix = '';
 
  // Make Data URL prefix for import image
  if ($type == 'import_img') {
    $info = getimagesize($file);
    if (!in_array($info['mime'], $allowedMimeTypesBySuffix)) {
      echo 'Disallowed MIME for supplied file';
      exit;
    }
    $prefix = 'data:' . $info['mime'] . ';base64,';
  }
?>
<html>
  <head>
  <meta charset="utf-8" />
  <title>-</title>
  <script>
 
top.svgEditor.processFile("<?php
 
// This should be safe since SVG edit does its own filtering (e.g., if an SVG file contains scripts)
echo $prefix . base64_encode($output);
 
?>", "<?php echo $type; ?>");
  </script>
</head>
<body></body>
</html>