export.php 996 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. include_once "archive/src/Parser.class.php";
  3. $type = $_REQUEST[ 'type' ];
  4. if ( $type === 'xmind' ) {
  5. $file = Parser::toXMind( $_REQUEST['data'] );
  6. } else if ( $type === 'freemind' ) {
  7. $file = Parser::toFreeMind( $_REQUEST['data'] );
  8. }
  9. if ( empty( $file ) ) {
  10. print 'parse error: empty data or data invalid!';
  11. die;
  12. }
  13. if (filesize( $file ) == 0) {
  14. http_response_code(500);
  15. echo "export failed.";
  16. die;
  17. }
  18. Header ( "Content-type: application/octet-stream" );
  19. Header ( "Accept-Ranges: bytes" );
  20. Header ( "Accept-Length: " . filesize ( $file ) );
  21. $download = isset($_REQUEST['download']);
  22. if ($download) {
  23. $downloadName = $_REQUEST[ 'filename' ];
  24. $downloadName = explode( ".", $downloadName );
  25. $downloadName = $downloadName[ 0 ];
  26. $T = array(
  27. 'xmind' => '.xmind',
  28. 'freemind' => '.mm'
  29. );
  30. Header ( "Content-Disposition: attachment; filename=" . urlencode($downloadName) . $T[ $type ] );
  31. }
  32. readfile( $file );
  33. unlink( $file );