I've noticed something strange. I've created a site for some warehouse - they want to show their products and all related documentation. So there is a form with 15 files for upload pdfs. During the tests I realised, that when uploading two identical files - only the first one is written. The rest has size 0. Is it the feature of HTTP, CGI.pm or Apache::ASP - or my code?
//hashes definitions
my %ki_pdf1 = qw (
f_field f_filepdf1 postfix _ki1 db_field pdf1 del_field f_delpdf1 );
...
my %ki_gfx1 = qw (
f_field f_filegfx1 postfix _ki1 db_field gfx1 del_field f_delgfx1 );my %pats = ( "kat_item", [ \%ki_pdf1, \%ki_pdf2, ..., \%ki_pdf15, \%ki_gfx1 ] );
sub upload_files {
my $fileup;
my $filehandle;
my $i;
my $in_buffer;
my $ext;
my $filecomm;
my $count;
for ( $i = 0 ; $i <= $#{$pats{$_[0]}} ; $i++ ) {
if ( $form->{$pats{$_[0]}[$i]{f_field}} ) {
$fileup = $Request->{FileUpload}{$pats{$_[0]}[$i]{f_field}};
$filehandle = $fileup->{FileHandle};
$_ = $fileup->{ContentType};
SWITCH: {
/image\/gif/ && do { $ext = ".gif"; $refresh = "yes"; last };
/image\/jpeg/ && do { $ext = ".jpg"; $refresh = "yes"; last };
/application\/pdf/ && do { $ext = ".pdf"; last };
}
my $localname = $_[1] . $pats{$_[0]}[$i]{postfix} . $ext;
$localname =~ /\w/;
$filehandle =~ /\w/;
$count = 0;
if ( sysopen( OUTPUT, "../files/" . $localname, 0x0601 ) ) {
while ( read( $filehandle, $in_buffer, 2048 ) ) {
print OUTPUT $in_buffer; $count++; }
$Session->{ErrorMesg} .= "$count buffers written to file $localname";
if ( $count == 0 ) { $Session->{ErrorMesg} .= "<b> - FAILED!</b><br>";
} else { $Session->{ErrorMesg} .= "<br>"; }
close OUTPUT;
$msth = $mdbh->prepare(
"UPDATE $_[0] SET $pats{$_[0]}[$i]{db_field}=? WHERE id=?" );
$msth->execute( ( $_[1] . $pats{$_[0]}[$i]{postfix} . $ext ), $_[1] );
}
}
$filecomm = ( $pats{$_[0]}[$i]{f_field} . "desc" );
if ( $form->{$filecomm} ) {
$msth = $mdbh->prepare(
"UPDATE $_[0] SET " . $pats{$_[0]}[$i]{db_field} .
"desc=? WHERE id=?" );
$msth->execute( $form->{$filecomm}, $_[1] );
}
}
}So, example call looks like this
sub save_kat {
//read data from text fields in form and insert it into database
//$prefix = item id in the database, smallint
upload_files( "kat_item", $prefix );
}Regards
-- CPU hotplug is not for removing the processor from single-CPU x86 box. Kiddie: "The new kernel has CPU hotplug support, here, watch... oh CRAP."
Bruno Czekay - bruno(at)domar.pl
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
