0) { $file = $_POST['filename'] . $suffix; } else { $file = 'image' . $suffix; } if($suffix == '.svg') { $mime = 'image/svg+xml'; $contents = rawurldecode($_POST['output_svg']); } else { $mime = 'image/png'; $contents = $_POST['output_png']; $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; ?>