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


In reply to Re^4: at job help ? by leocharre
in thread at job help ? by leocharre

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.