summaryrefslogtreecommitdiff
path: root/saveImg.cgi
blob: 0447d616d1a3f0c29bbb5806afd41265ed0ab43d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;