2010-07-06 13:57:05 +00:00
< ? php
/*
* filesave . php
* To be used with ext - server_opensave . js for SVG - edit
*
2012-09-16 18:53:27 +00:00
* Licensed under the MIT License
2010-07-06 13:57:05 +00:00
*
* Copyright ( c ) 2010 Alexis Deveria
*
*/
Support PNG, JPEG, BMP, WEBP export formats by change of "Export to PNG" menu item into "Export" with its own pull-down dialog (and a HTML5 range type input element for "quality" selection for JPEG or WEBP files), including changes for the server_opensave extension; change locale key from "export_png" to "export_img" and change the corresponding localized strings (currently CS, DE, ES, FR, IT, NL, PT-BR, RO, SK, all reset to English to avoid translation errors); within the setCustomHandlers() API, deprecate "pngsave" in favor of "exportImage" (chosen to avoid just using the simpler but reserved JS keyword "export") including use within the server_opensave extension; a few JSLint-friendly changes
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2602 eee81c28-f429-11dd-99c0-75d572ba1ddd
2013-10-28 03:53:30 +00:00
2014-02-01 16:13:51 +00:00
function encodeRFC5987ValueChars ( $str ) {
2018-05-18 06:41:43 +00:00
// See https://tools.ietf.org/html/rfc5987#section-3.2.1
// For better readability within headers, add back the characters escaped by rawurlencode but still allowable
// Although RFC3986 reserves "!" (%21), RFC5987 does not
return preg_replace_callback ( '@%(2[1346B]|5E|60|7C)@' , function ( $matches ) {
return chr ( '0x' . $matches [ 1 ]);
}, rawurlencode ( $str ));
2014-02-01 16:13:51 +00:00
}
2013-10-29 07:26:29 +00:00
require ( 'allowedMimeTypes.php' );
Support PNG, JPEG, BMP, WEBP export formats by change of "Export to PNG" menu item into "Export" with its own pull-down dialog (and a HTML5 range type input element for "quality" selection for JPEG or WEBP files), including changes for the server_opensave extension; change locale key from "export_png" to "export_img" and change the corresponding localized strings (currently CS, DE, ES, FR, IT, NL, PT-BR, RO, SK, all reset to English to avoid translation errors); within the setCustomHandlers() API, deprecate "pngsave" in favor of "exportImage" (chosen to avoid just using the simpler but reserved JS keyword "export") including use within the server_opensave extension; a few JSLint-friendly changes
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2602 eee81c28-f429-11dd-99c0-75d572ba1ddd
2013-10-28 03:53:30 +00:00
2014-06-13 08:16:47 +00:00
$mime = ( ! isset ( $_POST [ 'mime' ]) || ! in_array ( $_POST [ 'mime' ], $allowedMimeTypesBySuffix )) ? 'image/svg+xml;charset=UTF-8' : $_POST [ 'mime' ];
Support PNG, JPEG, BMP, WEBP export formats by change of "Export to PNG" menu item into "Export" with its own pull-down dialog (and a HTML5 range type input element for "quality" selection for JPEG or WEBP files), including changes for the server_opensave extension; change locale key from "export_png" to "export_img" and change the corresponding localized strings (currently CS, DE, ES, FR, IT, NL, PT-BR, RO, SK, all reset to English to avoid translation errors); within the setCustomHandlers() API, deprecate "pngsave" in favor of "exportImage" (chosen to avoid just using the simpler but reserved JS keyword "export") including use within the server_opensave extension; a few JSLint-friendly changes
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2602 eee81c28-f429-11dd-99c0-75d572ba1ddd
2013-10-28 03:53:30 +00:00
if ( ! isset ( $_POST [ 'output_svg' ]) && ! isset ( $_POST [ 'output_img' ])) {
2018-05-18 06:41:43 +00:00
die ( 'post fail' );
2010-07-06 13:57:05 +00:00
}
$file = '' ;
Support PNG, JPEG, BMP, WEBP export formats by change of "Export to PNG" menu item into "Export" with its own pull-down dialog (and a HTML5 range type input element for "quality" selection for JPEG or WEBP files), including changes for the server_opensave extension; change locale key from "export_png" to "export_img" and change the corresponding localized strings (currently CS, DE, ES, FR, IT, NL, PT-BR, RO, SK, all reset to English to avoid translation errors); within the setCustomHandlers() API, deprecate "pngsave" in favor of "exportImage" (chosen to avoid just using the simpler but reserved JS keyword "export") including use within the server_opensave extension; a few JSLint-friendly changes
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2602 eee81c28-f429-11dd-99c0-75d572ba1ddd
2013-10-28 03:53:30 +00:00
$suffix = '.' . array_search ( $mime , $allowedMimeTypesBySuffix );
2010-07-06 13:57:05 +00:00
Support PNG, JPEG, BMP, WEBP export formats by change of "Export to PNG" menu item into "Export" with its own pull-down dialog (and a HTML5 range type input element for "quality" selection for JPEG or WEBP files), including changes for the server_opensave extension; change locale key from "export_png" to "export_img" and change the corresponding localized strings (currently CS, DE, ES, FR, IT, NL, PT-BR, RO, SK, all reset to English to avoid translation errors); within the setCustomHandlers() API, deprecate "pngsave" in favor of "exportImage" (chosen to avoid just using the simpler but reserved JS keyword "export") including use within the server_opensave extension; a few JSLint-friendly changes
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2602 eee81c28-f429-11dd-99c0-75d572ba1ddd
2013-10-28 03:53:30 +00:00
if ( isset ( $_POST [ 'filename' ]) && strlen ( $_POST [ 'filename' ]) > 0 ) {
2018-05-18 06:41:43 +00:00
$file = $_POST [ 'filename' ] . $suffix ;
2010-07-06 13:57:05 +00:00
} else {
2018-05-18 06:41:43 +00:00
$file = 'image' . $suffix ;
2010-07-06 13:57:05 +00:00
}
Support PNG, JPEG, BMP, WEBP export formats by change of "Export to PNG" menu item into "Export" with its own pull-down dialog (and a HTML5 range type input element for "quality" selection for JPEG or WEBP files), including changes for the server_opensave extension; change locale key from "export_png" to "export_img" and change the corresponding localized strings (currently CS, DE, ES, FR, IT, NL, PT-BR, RO, SK, all reset to English to avoid translation errors); within the setCustomHandlers() API, deprecate "pngsave" in favor of "exportImage" (chosen to avoid just using the simpler but reserved JS keyword "export") including use within the server_opensave extension; a few JSLint-friendly changes
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2602 eee81c28-f429-11dd-99c0-75d572ba1ddd
2013-10-28 03:53:30 +00:00
if ( $suffix == '.svg' ) {
2018-05-18 06:41:43 +00:00
$contents = $_POST [ 'output_svg' ];
2010-07-06 13:57:05 +00:00
} else {
2018-05-18 06:41:43 +00:00
$contents = $_POST [ 'output_img' ];
$pos = ( strpos ( $contents , 'base64,' ) + 7 );
$contents = base64_decode ( substr ( $contents , $pos ));
2010-07-06 13:57:05 +00:00
}
2018-05-16 00:53:27 +00:00
header ( 'Cache-Control: public' );
header ( 'Content-Description: File Transfer' );
2014-02-01 16:13:51 +00:00
2018-05-18 04:40:50 +00:00
// See https://tools.ietf.org/html/rfc6266#section-4.1
2014-02-01 16:13:51 +00:00
header ( " Content-Disposition: attachment; filename*=UTF-8'' " . encodeRFC5987ValueChars (
2018-05-18 06:41:43 +00:00
// preg_replace('@[\\\\/:*?"<>|]@', '', $file) // If we wanted to strip Windows-disallowed characters server-side (but not a security issue, so we can strip client-side instead)
$file
2014-02-01 16:13:51 +00:00
));
2018-05-16 00:53:27 +00:00
header ( 'Content-Type: ' . $mime );
header ( 'Content-Transfer-Encoding: binary' );
2014-02-01 16:13:51 +00:00
echo $contents ;
2018-05-16 00:53:27 +00:00
?>