summaryrefslogtreecommitdiff
path: root/saveImg.cgi
diff options
context:
space:
mode:
Diffstat (limited to 'saveImg.cgi')
-rw-r--r--saveImg.cgi54
1 files changed, 54 insertions, 0 deletions
diff --git a/saveImg.cgi b/saveImg.cgi
new file mode 100644
index 0000000..0447d61
--- /dev/null
+++ b/saveImg.cgi
@@ -0,0 +1,54 @@
+#!/usr/bin/perl
+use strict;
+use CGI;
+use CGI::Carp qw ( fatalsToBrowser );
+use LWP::Simple;
+use MIME::Base64;
+
+##---------------------------------------------------------------------------------------
+##INPUT PARAMETERS THAT CAN BE CUSTOMIZED
+##---------------------------------------------------------------------------------------
+##Location of texture and heightmap files to be downloaded into
+my $outputDir="d:/tmp/files";
+##---------------------------------------------------------------------------------------
+##GET THE PICTURE NAME AND BASE64 DATA FROM THE HTTP POST REQUEST
+##---------------------------------------------------------------------------------------
+my $query = new CGI;
+##Get image name
+my $imageName = $query->param("name");
+if ( !$imageName )
+ {
+ ##Problem retrieving the data
+ print $query->header ( );
+ print "no";
+ exit;
+ }
+##Get encoded image
+my $encodedContents = $query->param("picture");
+if ( !$encodedContents )
+ {
+ ##Problem retrieving the data
+ print $query->header ( );
+ print "no";
+ exit;
+ }
+
+##---------------------------------------------------------------------------------------
+##GET HANDLE AND SAVE THE PICTURE CONTENTS TO THE OUTPUT DIR
+##---------------------------------------------------------------------------------------
+##Decode picture data
+my $decodedContents = decode_base64($encodedContents);
+
+##Save picture
+my $filename = $outputDir . "/" . $imageName;
+open(IMG,">$filename");
+binmode IMG;
+print IMG $decodedContents;
+close IMG;
+
+##---------------------------------------------------------------------------------------
+##PRINT SUCCESS IN HTML FORMAT
+##---------------------------------------------------------------------------------------
+print $query->header ( );
+print "yes";
+exit;