in reply to Re^3: at job help ?
in thread at job help ?

Ok.. update .. This is much better now, fixed some stupidity with mimetypes, this is actually important so the client will know what to do with the data.

i installed File::MMagic on the server and here's the code to my downloader.. i high-lighted what applies here.

#!/usr/bin/perl -T =pod DOWNLOAD A FILE does not need to be sent form data, it makes a temp download link +from the last selected file =cut use strict; use lib 'xxxxxxxxxxxx'; use DMS; use DMS::Admin; use DMS::Database; use DMS::Shared; use Hstat; use File::MMagic; #first test and sanitize all tainted data my %FD=DMS::tainted_data; #will poop out on its own if bad my $db=DMS::Database::dbstart; #///////// THIS IS THE DOG //////////////////////////////////////// +///// my %SV = DMS::Database::SV('u,m',\$db,\%FD); #then get all form data that may exist if ($SV{usertype} eq 'u'){ #make sure they have rights over file id my $c=$db->prepare(qq|select users_id from files_users where users +_id="$SV{users_id}" and inode="$SV{file_selected}"|); $c->execute; unless($c->rows){ #user has no rights to file. $c->finish; $db->disconnect; print "Location: $WWW?you.do.not.have.rights.to.that.file.u\n\ +n"; exit; } $c->finish; } elsif ($SV{usertype} eq 'm'){ #find parentmost's inode unless ( find_parentmost($SV{file_selected},\$db) eq $SV{project_s +elected} ){ $db->disconnect; print "Location: $WWW?you.have.no.rights.to.that.file.m.$SV{pr +oject_selected}.$SV{users_id}\n\n"; exit; } #$q->finish; } # else.. they are admin or superadmin. $db->disconnect; # #stream my $filename = $SV{file_selected_path};$filename=~s/^.+\///; # $DOC/$SV{file_selected_path} is something like /my/file/on/server/he +re.pdf my $FILE; if (!open($FILE, '<',"$DOC/$SV{file_selected_path}")) { print "Content-type: text/html\n\n Sorry $DOC/$SV{file_selected_path}"; exit; } #ok we are all go. #find out mime type!!! my $mm= new File::MMagic; #use internal magic file my $res = $mm->checktype_filename("$DOC/$SV{file_selected_path}"); print(qq|Content-Disposition: attachment; filename="$filename"\nConten +t-Type: $res\n\n|); binmode(STDOUT); binmode($FILE); $/ = \1024; # Read in blocks of 1024 bytes; print while <$FILE>; exit; # sub find_parentmost { my ($inode,$db)=@_; #my $parent=1; my $q=$$db->prepare(qq{SELECT link FROM files WHERE inode=?}); my $parentmost; while ($inode){ $q->execute($inode); $parentmost=$inode; ($inode) = ($q->fetchrow); } $q->finish; return $parentmost; }

Edit: g0n - replaced pre with code tags