serotta1958 has asked for the wisdom of the Perl Monks concerning the following question:

I am creating an educational web site that allows people to download lessons after browsing a mysql based catelog. All the web pages are secured using CGI Session but I cant figure out how to protect the download files. Is there a way to hide the filenames from the user? Or should I somehow use temporary filenames? Any suggestions would be appreciated!!

Replies are listed 'Best First'.
Re: Design Question on File Downloads
by Khen1950fx (Canon) on Aug 18, 2011 at 08:32 UTC
    You can "hide" the filenames by doing an url mask and by using a temporary filehandle. Here's an example. It's not MySQL, but it's the general idea:
    #!/usr/bin/perl use strict; use warnings; use CGI qw(param); use CGI::Session; my $session = CGI::Session->new(); $session->expire('5m'); $session->param( 'TestName', 'TestValue' ); my $sessionid = $session->id; $ENV{REMOTE_ADDR} = '127.0.0.1'; $session->flush; $session = CGI::Session->new($sessionid); CGI::Session->import('-ip_match'); $CGI::Session::IP_MATCH = 1; print "IP_MATCH is turned on\n"; if (my $cse = CGI::Session->load($sessionid)) { print "Session loaded\n"; } else { die CGI::Session->errstr(); } print $sessionid, "\n"; my $dir = '/root/Desktop'; my $file_id = param('/id_mod'); open my $fh, '<', $dir or die $@; my @fileholder = <$fh>; close $fh; print "Content-Type:application/x-download\n"; $session->flush;
    Updated: took out unnecessary code.
Re: Design Question on File Downloads
by Anonymous Monk on Aug 18, 2011 at 06:51 UTC

    All the web pages are secured using CGI Session

    Thats odd, CGI::Session doesn't provide security

    but I cant figure out how to protect the download files. Is there a way to hide the filenames from the user?

    The same way you're protecting the pages?

    Instead of having the webserver (apache) serve files, have your "pages" serve the files instead

    Any suggestions would be appreciated!!

    I could have sworn I've seen this wheel already, but I'd be darned if I can remember the name -- I would try looking for existing solution before inventing my own

      Isn't that wheel called moodle? ;)

        As long as it isn't called Blackboard... Ugh, that system is awful. Or at leat it used to be when I was in college, and I hear it hasn't gotten much better over time.