Good Evening,

I'm brand new to the site and perl so bear with me.

I have a cgi/perl script which works fine except I wish to check the size of a directory as a client adds files and issus a warning. The problem is the result always seems to give me an erroneous value. I have been dealing with a person at the Experts-Exchange and hs basically has given up after a week and suggested I ask you.

Rather than post all that has been done he suggested pointing to their response page.

This has the history of the incident. My host is running linux, and Apache server 1.3.27(unix) and perl 5.006001. The code is listed below.

#!/usr/bin/perl -w use CGI; @valid = ('theartistloft.com'); $maxfoldersize = "200000"; $query = new CGI; $comments = $query->param("Comments"); $filename = $query->param("file_name"); $fsize = -s $filename; $email_address = $query->param("email_address"); #! try to create directory $upload_dir = "/home/bsexton/public_html/NEWClients/$email_address"; unless (-d "$upload_dir"){ mkdir ("$upload_dir", 0777); chmod(0777, "$upload_dir"); } #! end of create directory $filename =~ s/.*[\/\\](.*)/$1/; $upload_filehandle = $query->upload("file_name"); open UPLOADFILE, ">$upload_dir/$filename"; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE; $filename1 = $query->param("file_name1"); $fsize1 = -s $filename1; $filename1 =~ s/.*[\/\\](.*)/$1/; #! End of Folder Check $upload_filehandle = $query->upload("file_name1"); open UPLOADFILE, ">$upload_dir/$filename1"; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE; $filename2 = $query->param("file_name2"); $fsize2 = -s $filename2; $filename2 =~ s/.*[\/\\](.*)/$1/; $upload_filehandle = $query->upload("file_name2"); open UPLOADFILE, ">$upload_dir/$filename2"; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE; $filename3 = $query->param("file_name3"); $fsize3 = -s $filename3; $filename3 =~ s/.*[\/\\](.*)/$1/; $upload_filehandle = $query->upload("file_name3"); open UPLOADFILE, ">$upload_dir/$filename3"; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE; $todays_upload = $fsize + $fsize1 + $fsize2 + $fsize3; print $query->header ( ); #! Check Folder Size use File::Find; $File::Find::dir = $upload_dir; my $total_size = 0; find(sub { $total_size += -s }, @ARGV ? @ARGV : '.'); if ($total_size > $maxfoldersize) { print"You have exceded your limit of $maxfoldersize KB for the directo +ry $email_address \n"; } #! End of Folder Check $from = 'sales@theartistloft.com'; $subject = 'New Artist Loft Signup'; open(MAIL, "|/usr/sbin/sendmail -t"); print MAIL "To: $email_address\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; print MAIL "Dear Client:\n\n"; print MAIL "Thank you for signing up for The Artist Loft.\n\n"; print MAIL "This message is to confirm your transmission of $filename, + $filename1, $filename2, $filename3 from your PC today.\n\n"; print MAIL "Your Comments: $comments\n\n"; print MAIL "For future upload modifications and use of the chatroom, p +lease use the following information.\n\n"; print MAIL "Username = The Artist Loft\n"; print MAIL "Password = demo\n\n"; print MAIL "REMEMBER: username and password are case sensitive\n\n"; print MAIL "Thank you.\n"; print MAIL "Sales Department\n"; print MAIL "The Artist Loft\n"; close(MAIL); $to = 'newclient@theartistloft.com'; $from = 'sales@theartistloft.com'; $subject = 'A New Artist Loft Cleint'; open(MAIL, "|/usr/sbin/sendmail -t"); print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; print MAIL "Dear Sales Department:\n\n"; print MAIL "This message is to confirm transmission of $filename($fsiz +e), $filename1($fsize1), $filename2($fsize2), $filename3($fsize3) fro +m our new client $email_address today. Todays total was $todays_uploa +d bytes.\n\n"; print MAIL "Client Comments: $comments\n\n"; print MAIL "The Artist Loft\n\n"; print MAIL "Size of Directory $email_address = $total_size\n"; close(MAIL); print <<END_HTML; <HTML> <HEAD> <TITLE>Thanks!</TITLE> </HEAD> <BODY> <P align="center">&nbsp;</P> <P align="center"><b><font size="5">Thanks for uploading your file!</f +ont></b></P> <P align="center"><b><font size="4">Your email address: $email_address +</font></b></P> <P align="center"><b><font size="4">Your file(s): $filename, $filename +1, $filename2, $filename3</font></b></P> </BODY> </HTML> END_HTML

Edited: ~Thu Nov 21 23:15:49 2002 (GMT) by footpad: Added <HTML> (and <READMORE>) formatting tags. Also retitled node and replies (was "Stumped Newbie") to aid future searching, per Consideration


In reply to Stumped with File::Find and -s by bsexton1qBob Sexton

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.