Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 103 lines (80 sloc) 2.448 kB
eefb40e @eolsson Added exporting server to repository
eolsson authored
1 <?php
2 /**
3 * This file is part of the exporting module for Highcharts JS.
4 * www.highcharts.com/license
5 *
6 *
7 * Available POST variables:
8 *
b455642 Fixed typo in the exporting server wrapper
highslide-software authored
9 * $filename string The desired filename without extension
10 * $type string The MIME type for export.
11 * $width int The pixel width of the exported raster image. The height is calculated.
12 * $svg string The SVG source code to convert.
eefb40e @eolsson Added exporting server to repository
eolsson authored
13 */
14
15
16 // Options
17 define ('BATIK_PATH', 'batik-rasterizer.jar');
18
19 ///////////////////////////////////////////////////////////////////////////////
20 ini_set('magic_quotes_gpc', 'off');
21
22 $type = $_POST['type'];
23 $svg = (string) $_POST['svg'];
24 $filename = (string) $_POST['filename'];
25
26 // prepare variables
27 if (!$filename) $filename = 'chart';
28 if (get_magic_quotes_gpc()) {
29 $svg = stripslashes($svg);
30 }
31
32
33
34 $tempName = md5(rand());
35
36 // allow no other than predefined types
37 if ($type == 'image/png') {
38 $typeString = '-m image/png';
39 $ext = 'png';
40
41 } elseif ($type == 'image/jpeg') {
42 $typeString = '-m image/jpeg';
43 $ext = 'jpg';
44
45 } elseif ($type == 'application/pdf') {
46 $typeString = '-m application/pdf';
47 $ext = 'pdf';
48
49 } elseif ($type == 'image/svg+xml') {
50 $ext = 'svg';
51 }
52 $outfile = "temp/$tempName.$ext";
53
54 if (isset($typeString)) {
55
56 // size
57 if ($_POST['width']) {
58 $width = (int)$_POST['width'];
59 if ($width) $width = "-w $width";
60 }
61
62 // generate the temporary file
63 if (!file_put_contents("temp/$tempName.svg", $svg)) {
64 die("Couldn't create temporary file. Check that the directory permissions for
65 the /temp directory are set to 777.");
66 }
67
68 // do the conversion
69 $output = shell_exec("java -jar ". BATIK_PATH ." $typeString -d $outfile $width temp/$tempName.svg");
70
71 // catch error
72 if (!is_file($outfile) || filesize($outfile) < 10) {
73 echo "<pre>$output</pre>";
25b7c53 Better debugging in export service
highslide-software authored
74 echo "Error while converting SVG. ";
75
76 if (strpos($output, 'SVGConverter.error.while.rasterizing.file') !== false) {
77 echo "SVG code for debugging: <hr/>";
78 echo htmlentities($svg);
79 }
eefb40e @eolsson Added exporting server to repository
eolsson authored
80 }
81
82 // stream it
83 else {
40f9388 Fixed wrong filename for exporting in Firefox when exporting.filename…
highslide-software authored
84 header("Content-Disposition: attachment; filename=\"$filename.$ext\"");
eefb40e @eolsson Added exporting server to repository
eolsson authored
85 header("Content-Type: $type");
86 echo file_get_contents($outfile);
87 }
88
89 // delete it
90 unlink("temp/$tempName.svg");
91 unlink($outfile);
92
93 // SVG can be streamed directly back
94 } else if ($ext == 'svg') {
40f9388 Fixed wrong filename for exporting in Firefox when exporting.filename…
highslide-software authored
95 header("Content-Disposition: attachment; filename=\"$filename.$ext\"");
eefb40e @eolsson Added exporting server to repository
eolsson authored
96 header("Content-Type: $type");
97 echo $svg;
98
99 } else {
100 echo "Invalid type";
101 }
102 ?>
Something went wrong with that request. Please try again.