Answer the question
In order to leave comments, you need to log in
Perl save data from input field on button click?
Good afternoon, tell me how to save data from the input field to a text document on the server, and after saving, a link to this file came out?
It seems to do everything, but does not save data to a file
#!c:\Perl64\bin\perl.exe
print "Content-type: text/html\n\n";
print "<html>\n";
print "\t<head>\n";
print "\t\t<title>Test</title>\n";
print "\t</head>\n";
print "\t<body>\n";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$input{$name} = $value;
}
# Save the user output in a file
$targetfile = "C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\RINTE\names.txt";
open (NAMEFILE, ">>$targetfile");
print NAMEFILE "Name: ",$input{'user_name'},"\n";
close (NAMEFILE);
# Send a message back to the user
print "Content-Type: text/html\n\n";
print "<h4>Thx for edditing the information</h4>\nPress ";
print '<a href="http://localhost:8080/RINTE/names.txt">here</a>';
print ", to see your data.\n";
print "<h4>Name: ",$input{'user_name'},"</h4>\n";
print "\t</body>\n";
print "</html>\n";
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question