Hallo
Habe da ein ziemliches Problem.
Habe hier ein Script das automatisch daten aus einen Submitter in ein Formularfeld eintragen soll.
leider stehen die Daten immer ganz unten auf der Seite und nicht in den Formularfeldern. Muß dort unter anderem einen xmlstring angeben,
aber wo bekomm ich den her und was ist das ?
Vielen Dank
#!/usr/bin/perl
#
# Version vom 10.12.03
#
# perl V 5.6.1 oder groesser notwendig
#
#
use strict;
use CGI qw(:standart);
use CGI::Carp qw(fatalsToBrowser);
use Fcntl qw(EFAULT);
use vars qw($lastError);
my $q = CGI->new();
print "Content-Type: text/html\n\n";
#read input parameters
my $name = $q->param("name");
my $title = $q->param("title");
my $vorschau = $q->param("vorschau");
my $bilder = $q->param("bilder");
my $description = $q->param("description");
my $email = $q->param("email");
my $url = $q->param("url");
my $cat = $q->param("cat");
my $submit = $q->param("submit");
my $link = $q->param("link");
my $xml = $q->param("$xml");
# Get the current time.
my($date) = scalar(localtime());
# Append the data to a file.
open(F, ">>/srv/www/htdocs/web80/html/tgp/add.php");
print F "From $0 at $date\n";
#for $key (keys %CGI) {
# print F "$key => $CGI{$key}\n";
#}
print F "Name: $name \n";
print F "Titel: $title \n";
print F "Vorschau: $vorschau \n";
print F "Anzahl: $bilder \n";
print F "Beschreibung: $description \n";
print F "Email: $email \n";
print F "URL: $url \n";
print F "Kategorie: $cat \n";
print F "Action: $submit \n";
print F "link: $link \n";
print F "Submit: $submit \n";
print F "XML-String: $xml \n";
close(F);
#print "<pre>\n";
receiveAdsImage($q) or die ("FATAL: receiveAdsImage fatal error: ".defined($lastError)?$lastError:$!."\n");
my $resHash;
$resHash->{'30'} = escapeString('30');
$resHash->{'link'} = escapeString('http://www.************pics.fuckerton.de');
$resHash->{'comment'} = escapeString('so geht ab');
printXMLResponce($resHash);
#print "</pre>\n";
exit;
#recieve and store advert image file if exist
sub receiveAdsImage {
my($query) = @_;
$lastError = undef;
unless (defined($query->param('asimage')) && ($query->param('asimage') !~ /^\w*$/)) {
return 1;
} else {
#T print $query->param('asimage')."<br>\n";
my $file = $query->upload('asimage');
my $fileinfo = $query->uploadInfo($file);
my $fileext;
#determine file name as transmitted (full path may be included)
my $filename = getFileName($file,$query->uploadInfo($file)->{'Content-Disposition'});
#determine file extension
if ($filename =~ /\.(jpg|jpeg|gif|png)$/i) {
$fileext = lc($1);
} else {
$lastError = "Falscher Typ der Bild-Datei. Nur jpeg (jpg), png, gif sind erlaubt.";
return;
}
#genertate random file name
#my $fileID = generateID(10);
my $advertID = $q->param("advertID");
my $fileID = "pic-$advertID";
#compose complete file name with random name and determined extension
my $storeFile = "$fileID.$fileext";
#Tprint "Size $storeFile= $filesize\n<br>";
if (!$file && $query->cgi_error) {
$lastError = "Fehler beim Holen der Bild-Datei im CGI.";
return;
}
if (not sysopen FILE, "$storeFile", O_EXCL | O_CREAT | O_WRONLY, 0600) {
$lastError = "Fehler bei der Erzeugung der Bild-Datei. ($!)";
return;
} else {
my $buffer = "";
my $BUFFER_1K = 1024;
my ($fsize,$rsize) = (0,0);
binmode FILE;
while (($rsize = read ($file, $buffer, $BUFFER_1K))) {
print FILE $buffer or return; #print("Fehler beim Schreiben der Bild-Datei. ($!)\n");
$fsize += $rsize;
}
close FILE;
# print ("Store image file (name=$storeFile,size = $fsize)\n");
return 2;
}
}
}
#Used in receiveAdsImage function
sub getFileName {
my ($cginame, $disp) = @_;
my $name;
if ($disp =~ /filename\=\"(.+)\"/) {
$name = ($1);
} else {
$name = $cginame;
}
return $name;
}
#generate random string $idSize chars length
sub generateID {
my $idSize = shift;
$idSize = 8 if not defined($idSize);
my @chars = ("A".."Z","a".."z",1..9);
return join("", @chars[ map{rand @chars} (1..$idSize) ]);
}
sub escapeString {
my $res = shift;
$res =~ s/\&/\&/g;
$res =~ s/\</\</g;
$res =~ s/\>/\>/g;
$res =~ s/\"/\"/g;
$res =~ s/\'/\'/g;
return $res;
}
sub printXMLResponce {
$resHash = shift;
print <<HTMLTEXT;
<?xml version="1.0" encoding="ISO-8859-1"?>
<advertreturn>
<advertduration>$resHash->{'duration'}</advertduration>
<advertlink>$resHash->{'link'}</advertlink>
<comment>$resHash->{'comment'}</comment>
</advertreturn>
HTMLTEXT
}
Habe da ein ziemliches Problem.
Habe hier ein Script das automatisch daten aus einen Submitter in ein Formularfeld eintragen soll.
leider stehen die Daten immer ganz unten auf der Seite und nicht in den Formularfeldern. Muß dort unter anderem einen xmlstring angeben,
aber wo bekomm ich den her und was ist das ?
Vielen Dank
#!/usr/bin/perl
#
# Version vom 10.12.03
#
# perl V 5.6.1 oder groesser notwendig
#
#
use strict;
use CGI qw(:standart);
use CGI::Carp qw(fatalsToBrowser);
use Fcntl qw(EFAULT);
use vars qw($lastError);
my $q = CGI->new();
print "Content-Type: text/html\n\n";
#read input parameters
my $name = $q->param("name");
my $title = $q->param("title");
my $vorschau = $q->param("vorschau");
my $bilder = $q->param("bilder");
my $description = $q->param("description");
my $email = $q->param("email");
my $url = $q->param("url");
my $cat = $q->param("cat");
my $submit = $q->param("submit");
my $link = $q->param("link");
my $xml = $q->param("$xml");
# Get the current time.
my($date) = scalar(localtime());
# Append the data to a file.
open(F, ">>/srv/www/htdocs/web80/html/tgp/add.php");
print F "From $0 at $date\n";
#for $key (keys %CGI) {
# print F "$key => $CGI{$key}\n";
#}
print F "Name: $name \n";
print F "Titel: $title \n";
print F "Vorschau: $vorschau \n";
print F "Anzahl: $bilder \n";
print F "Beschreibung: $description \n";
print F "Email: $email \n";
print F "URL: $url \n";
print F "Kategorie: $cat \n";
print F "Action: $submit \n";
print F "link: $link \n";
print F "Submit: $submit \n";
print F "XML-String: $xml \n";
close(F);
#print "<pre>\n";
receiveAdsImage($q) or die ("FATAL: receiveAdsImage fatal error: ".defined($lastError)?$lastError:$!."\n");
my $resHash;
$resHash->{'30'} = escapeString('30');
$resHash->{'link'} = escapeString('http://www.************pics.fuckerton.de');
$resHash->{'comment'} = escapeString('so geht ab');
printXMLResponce($resHash);
#print "</pre>\n";
exit;
#recieve and store advert image file if exist
sub receiveAdsImage {
my($query) = @_;
$lastError = undef;
unless (defined($query->param('asimage')) && ($query->param('asimage') !~ /^\w*$/)) {
return 1;
} else {
#T print $query->param('asimage')."<br>\n";
my $file = $query->upload('asimage');
my $fileinfo = $query->uploadInfo($file);
my $fileext;
#determine file name as transmitted (full path may be included)
my $filename = getFileName($file,$query->uploadInfo($file)->{'Content-Disposition'});
#determine file extension
if ($filename =~ /\.(jpg|jpeg|gif|png)$/i) {
$fileext = lc($1);
} else {
$lastError = "Falscher Typ der Bild-Datei. Nur jpeg (jpg), png, gif sind erlaubt.";
return;
}
#genertate random file name
#my $fileID = generateID(10);
my $advertID = $q->param("advertID");
my $fileID = "pic-$advertID";
#compose complete file name with random name and determined extension
my $storeFile = "$fileID.$fileext";
#Tprint "Size $storeFile= $filesize\n<br>";
if (!$file && $query->cgi_error) {
$lastError = "Fehler beim Holen der Bild-Datei im CGI.";
return;
}
if (not sysopen FILE, "$storeFile", O_EXCL | O_CREAT | O_WRONLY, 0600) {
$lastError = "Fehler bei der Erzeugung der Bild-Datei. ($!)";
return;
} else {
my $buffer = "";
my $BUFFER_1K = 1024;
my ($fsize,$rsize) = (0,0);
binmode FILE;
while (($rsize = read ($file, $buffer, $BUFFER_1K))) {
print FILE $buffer or return; #print("Fehler beim Schreiben der Bild-Datei. ($!)\n");
$fsize += $rsize;
}
close FILE;
# print ("Store image file (name=$storeFile,size = $fsize)\n");
return 2;
}
}
}
#Used in receiveAdsImage function
sub getFileName {
my ($cginame, $disp) = @_;
my $name;
if ($disp =~ /filename\=\"(.+)\"/) {
$name = ($1);
} else {
$name = $cginame;
}
return $name;
}
#generate random string $idSize chars length
sub generateID {
my $idSize = shift;
$idSize = 8 if not defined($idSize);
my @chars = ("A".."Z","a".."z",1..9);
return join("", @chars[ map{rand @chars} (1..$idSize) ]);
}
sub escapeString {
my $res = shift;
$res =~ s/\&/\&/g;
$res =~ s/\</\</g;
$res =~ s/\>/\>/g;
$res =~ s/\"/\"/g;
$res =~ s/\'/\'/g;
return $res;
}
sub printXMLResponce {
$resHash = shift;
print <<HTMLTEXT;
<?xml version="1.0" encoding="ISO-8859-1"?>
<advertreturn>
<advertduration>$resHash->{'duration'}</advertduration>
<advertlink>$resHash->{'link'}</advertlink>
<comment>$resHash->{'comment'}</comment>
</advertreturn>
HTMLTEXT
}
Kommentar