You seem to have two questions here.

  1. How do I stop my hard drive from filling up when someone posts some data that I save to a file?
  2. How do I password protect a page?

These are two completely separate issues. It appears that you have a problem (don't want your hard drive filled up) and you are asking how to implement your solution. That's kind of like asking how to peel potatos with a cheese grater. You can do it, but it's not really what you're looking for :)

Question 1: you can use CGI::Safe to conveniently set a max post size for your uploads (you'll want to read the documentation on how to allow uploads). Then, when you save the file, you'll want to check that the file size plus the current directory size doesn't exceed the max directory size that you have set. From "CGI Programming with Perl", 2nd Edition (by O'Reilly):

use constant MAX_DIR_SIZE => 100 * 1_048_576; # max of 100 MB use constant UPLOAD_DIR => "/path/to/upload/dir"; # later if ( dir_size( UPLOAD_DIR ) + $ENV{CONTENT_LENGTH} > MAX_DIR_SIZE ) { # don't allow the upload } # later sub dir_size { my $dir = shift; my $dir_size = 0; opendir DIR, $dir or die "Unable to open $dir: $!"; while ( readdir DIR ) { $dir_size += -s "$dir/$_"; } return $dir_size; }

As for password protecting your pages, there are many ways to do this. You could use .htaccess files (but those don't allow a timeout), but make sure you use them over an encrypted connection. There are other ways, too. I'm sure some other monks can help you here. I need to get back to work :)

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to (Ovid) Re: Password Protection for Web Page. by Ovid
in thread Password Protection for Web Page. by augamecock

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.