filesave.php 994 B

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