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

Features to Upload-Function

Quote Reply
Features to Upload-Function
I have combine the passwort-mod (Modify) and the fileupload-mod at my Links2; at this doing i remember that alex asks for ideas to the upload for sql. Think filesize, file-typ are clear, butīs how with the picsize in width and heigth?? I have found this code in another script i use, but im not that programmer understanding it. Maybe it helps someone interested in:


sub ProcessUpld {

my ( $filename ) = @_;
my ( $width, $height );
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat( $filename );

if ( substr ( $filename, -4, 4 ) eq ".gif" ) {
open ( FILE, $filename );
my $head;
my $gHeadFmt = "A6vvb8CC";
my $pictDescFmt = "vvvvb8";
read FILE, $head, 13;
(my $GIF8xa, $width, $height, my $resFlags, my $bgColor, my $w2h) = unpack $gHeadFmt, $head;
close FILE;
$PhotoWidth = $width;
$PhotoHeight = $height;
$PhotoSize = $size;
return;
}

if ( substr ( $filename, -4, 4 ) eq ".jpg" ) {
open ( FILE, $filename );
binmode ( FILE );
my($done)=0;
my($c1,$c2,$ch,$s,$length, $dummy)=(0,0,0,0,0,0);
my($a,$b,$c,$d);

if ( read(FILE, $c1, 1) &&
read(FILE, $c2, 1) &&
ord($c1) == 0xFF &&
ord($c2) == 0xD8 )
{
while (ord($ch) != 0xDA && !$done) {
while (ord($ch) != 0xFF) { return(0,0) unless read(FILE, $ch, 1); }
while (ord($ch) == 0xFF) { return(0,0) unless read(FILE, $ch, 1); }

if ((ord($ch) >= 0xC0) && (ord($ch) <= 0xC3)) {
return(0,0) unless read (FILE, $dummy, 3);
return(0,0) unless read(FILE, $s, 4);
($a,$b,$c,$d)= unpack("C"x4,$s);
$PhotoWidth = ($c<<8|$d);
$PhotoHeight = ($a<<8|$b);
$PhotoSize = $size;
return;
}else{
return(0,0) unless read (FILE, $s, 2);
($c1, $c2) = unpack("C"x2,$s);
$length = $c1<<8|$c2;
last if (!defined($length) | | $length < 2);
read(FILE, $dummy, $length-2);
}
}
}
return (0,0);
}
return (0,0);
}


[This message has been edited by Robert (edited December 25, 1999).]
Quote Reply
Re: Features to Upload-Function In reply to
You could add two fields to Links called width and height. Then copy that info into add.cgi right after:

if ($id) {

add:

my $ins_rec = $db->get_record ($id, 'HASH')
my $att_list = $db->attach_list ($id);
my ($width, $height) = &ProcessUpld ($att_list->[0]->{ServerName});
$ins_rec->{Width} = $width;
$ins_rec->{Height} = $height;
$db->modify_record ($ins_rec);

What this does line by line is:

1. Get the hash ref of the record you just added.
2. Get a array ref of hash refs of attachments for this record (as one record can have more then one attachment).
3. Use ProcessUpl to calculate the width and height of the uploaded file. Note: You will need to edit this subroutine, as it quits out if the file does not end in .gif, and Links SQL does not keep the file extensions in place.
4,5. Set the width and height.
6. Save the record back into the database.

It may take a little more tinkering, but this should get you on the right path.

Cheers,

Alex
Quote Reply
Re: Features to Upload-Function In reply to
I think Jerry (Widgetz) has been playing with this and might be able to put it into a form that works for everyone.

I have a bunch of 3rd party modules installed for graphics, that make finding the picture information easier, but it means getting and installing those modules, rather than a short piece of code.

Any graphics upload should be able to handle .gif, .jpg and .png files. GD.pm no longer handles .gif

Also, you need to remember that .jpg files might also have .jpe and .jpeg extensions, and that you should lower-case the extension before testing for it, in case someone uploads a file theirfile.GIF

A file-upload program should really have this sort of checking available, and if we can come up with a set of routines maybe we can get them added as part of the Link SQL file-upload routine. If someone uploads an image, it's automatically checked, and the size information added to the database.
Quote Reply
Re: Features to Upload-Function In reply to
oh.. yea.. i made some routines to check for the size of images awhile back..

they are much shorter than that code above Smile

something i need to figure out right now is how to get the Attachments to work! Smile

Right now I just get a bunch of errors like NO Links_Attach or something..

jerry
Quote Reply
Re: Features to Upload-Function In reply to
Well, how about sharing some code, and maybe a group effort will develop.

------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/







Quote Reply
Re: Features to Upload-Function In reply to
i'm trying to figure out how to use attachments first! Smile

jerry
Quote Reply
Re: Features to Upload-Function In reply to
Which part is giving you the trouble?