fileopen.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <!DOCTYPE html>
  2. <?php
  3. exit;
  4. /*
  5. * fileopen.php
  6. * To be used with ext-server_opensave.js for SVG-edit
  7. *
  8. * Licensed under the MIT License
  9. *
  10. * Copyright(c) 2010 Alexis Deveria
  11. *
  12. */
  13. // Very minimal PHP file, all we do is Base64 encode the uploaded file and
  14. // return it to the editor
  15. $type = $_REQUEST['type'];
  16. if (!in_array($type, array('load_svg', 'import_svg', 'import_img'))) {
  17. exit;
  18. }
  19. require('allowedMimeTypes.php');
  20. $file = $_FILES['svg_file']['tmp_name'];
  21. $output = file_get_contents($file);
  22. $prefix = '';
  23. // Make Data URL prefix for import image
  24. if ($type == 'import_img') {
  25. $info = getimagesize($file);
  26. if (!in_array($info['mime'], $allowedMimeTypesBySuffix)) {
  27. exit;
  28. }
  29. $prefix = 'data:' . $info['mime'] . ';base64,';
  30. }
  31. ?>
  32. <html xmlns="http://www.w3.org/1999/xhtml">
  33. <head>
  34. <meta charset="utf-8" />
  35. <script>
  36. top.svgEditor.processFile("<?php
  37. // This should be safe since SVG edit does its own filtering (e.g., if an SVG file contains scripts)
  38. echo $prefix . base64_encode($output);
  39. ?>", "<?php echo $type; ?>");
  40. </script>
  41. </head><body></body>
  42. </html>