I was working on client program in pure html/javascript which would be able to send the folder, file and its contents as paramaters in a post request to the target cgi script (i.e saveFile.cgi ).
I am able to retrieve the data from the post request , but i am unable to create a file/folder using these form data in the script, yet i am able to print these values using print.
Also, I am able to create file/folder using the exact string literal which I was trying to retrieve from the post request.I am not understanding where i am going wrong.
I am programming in a windows environment:
Client Code :
var data = {
"folder": variant,
"file" : "metadata.json",
"content": response
};
$.post('../cgi-bin/demos/saveJSON.cgi', data, function(resp) {
// Do something with the request
}, 'json');
Server-Side/CGI Script:
#!C:\perl\bin\perl.exe -wT
use CGI;
use JSON;
print "Content-type: text/html\n\n";
$query = new CGI;
$folder = $query->param("folder");
$file = $query->param("file");
$content = $query->param("content");
#print "Folder " . $folder ."<br/>";
#print "File " . $file ."<br/>";
#print "Content " . $content ."<br/>";
mkdir($folder, 0700) unless(-d $folder);
open(OS,">$folder/$file") or die("Cannot write to file");
print OS $content;
close(OS);