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
|
|
|
|
|
|
|
$allowedMimeTypesBySuffix = array(
|
|
|
|
'svg' => 'image/svg+xml',
|
|
|
|
'png' => 'image/png',
|
|
|
|
'jpeg' => 'image/jpeg',
|
|
|
|
'bmp' => 'image/bmp',
|
|
|
|
'webp' => 'image/webp'
|
|
|
|
);
|
|
|
|
|
|
|
|
$mime = !isset($_POST['mime']) || !in_array($_POST['mime'], $allowedMimeTypesBySuffix) ? 'image/svg+xml' : $_POST['mime'];
|
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['output_svg']) && !isset($_POST['output_img'])) {
|
2010-07-06 13:57:05 +00:00
|
|
|
die('post fail');
|
|
|
|
}
|
|
|
|
|
|
|
|
$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) {
|
2010-07-06 13:57:05 +00:00
|
|
|
$file = $_POST['filename'] . $suffix;
|
|
|
|
} else {
|
|
|
|
$file = 'image' . $suffix;
|
|
|
|
}
|
|
|
|
|
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') {
|
2010-07-06 13:57:05 +00:00
|
|
|
$contents = rawurldecode($_POST['output_svg']);
|
|
|
|
} else {
|
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
|
|
|
$contents = $_POST['output_img'];
|
2010-07-06 13:57:05 +00:00
|
|
|
$pos = (strpos($contents, 'base64,') + 7);
|
|
|
|
$contents = base64_decode(substr($contents, $pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
header("Cache-Control: public");
|
|
|
|
header("Content-Description: File Transfer");
|
|
|
|
header("Content-Disposition: attachment; filename=" . $file);
|
|
|
|
header("Content-Type: " . $mime);
|
|
|
|
header("Content-Transfer-Encoding: binary");
|
|
|
|
|
|
|
|
echo $contents;
|
|
|
|
|
|
|
|
?>
|