package MyApache::SF_Upload; ... use vars qw($UPLOAD_DIR $dir_size); sub handler { ... # Check that the directory is not getting full. $dir_size = 0; my $dirsz = dir_size( $UPLOAD_DIR ."/$dad" ); if ( $dirsz > MAX_DIR_SIZE ) { $apr->log_error("Upload directory is nearly full, $dirsz" ); return 507; # HTTP_INSUFFICIENT_STORAGE } $apr->warn("Upload directory is nearly full, $dirsz" ); ... } sub dir_size { my $dir = shift; # Loop through files and sum the sizes; this will descend down subdirs opendir DIR, $dir or die "Unable to open $dir: $!"; while ( $_ = readdir DIR ) { stat("$dir/$_"); if (-d _ ) { $dir_size += dir_size("$dir/$_") unless ($_ eq "." || $_ eq ".."); } else { $dir_size += -s _ ; } warn("DIR filename: $dir/$_ at $dir_size"); } return $dir_size; }