Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Weird attach

Quote Reply
Weird attach
Hmmm. I cant figure how turn this great feature to work.
Testing attachments I encountered some minor problems but the biggest :-( is that in some cases, including 100% of jpg files and 70% of gif files and never using plain/html, files are not displayed correctly on the .fil extension.
This happen everywhere.. accessing them directly, using jump.cgi and also admin.cgi.

I'm using very recent IE and Netscape and also tryed to change the local (test) server from IIS to Apache for win last release. I cannot figure where and why of this problem .

Does anydody have the same problem? How can I fix it?

thanks in advance

lepo
Quote Reply
Re: Weird attach In reply to
Yeeeee! found the problem! just added BINMODE and everything started to work great!

here's my mod:

on DBSQL.pm...
Code:
sub attach_file {
# --------------------------------------------------------
# Attaches a file to a record.
#
my ($self, $data_id, $field, $in) = @_;
(defined $self->{attach_dir}) or return $self->error('NOATTACHDIR');
(ref $in eq 'CGI') or return $self->error('BADARGS', 'attach_file', $in);
($in->param($field)) or return undef;
$self->connect();
my ($fh, $ft, $fn, $out, $size, $table, $query, $sth, $read, $buffer, $id, $name);
# Let's get the filetype, and filename.
$fh = $in->param($field) or return undef;
$ft = $in->uploadInfo($fh) ? $in->uploadInfo($fh)->{'Content-Type'} : 'application/octet-stream';
$fh =~ s,(.*)([/\\])([^/\\]+)$,defined $2 ? $3 : "$1$2$3",e;
$fn = $fh;
$fh = $in->param($field);
$out = $self->{attach_dir} . "/$data_id.$fn.fil";
open (OUT, "> $out") or return $self->error ('CANTOPEN', $out, $!);
binmode (OUT); # For those O/S that care.
while ($read = read ($fh, $buffer, 1024)) {
print OUT $buffer;
}
close OUT;
$size = -s $out;

# Save the info to the attachment table.
$table = $self->{db_table} . "_Attach";
$name = $fn ? $DBH->quote("$data_id.$fn.fil") : "''";
$fn = $fn ? $DBH->quote($fn) : "''";
$ft = $ft ? $DBH->quote($ft) : "''";
$query = qq~
INSERT INTO $table (ID, DataID, ServerName, FileName, FileType, FileSize)
VALUES (?, $data_id, $name , $fn, $ft, $size)
~;
$sth = $DBH->prepare($query) or return $self->error ('CANTPREPARE', $query, $DBI::errstr);
$id = $self->_pre_get_id ($sth, $table);
$sth->execute($id) or return $self->error ('CANTEXECUTE', $query, $DBI::errstr);
$id | |= $self->_post_get_id ($sth, $table);

# Return the data id.
return $id;
}

this routine allow me also to add multiple attachments without overwrite existents.

obvously this is the simplest way to turn things work. It's supposed to transfer only in binary mode so should be changed (I guess) for text/html file attachments.

hope that helps

cheers

lepo