#!/usr/bin/perl $upload_path = "/Users/james/xgrid_drop"; $finished_location = "/Users/james/xgrid_drop/finished"; # Allowed file list info: @allowed_file_list = ("Avenger", "Banshee", "Daredevil", "DarkFog", "Dritver", "Elephant", "Falcon", "Gorilla", "Grunt", "Kicker", "Lancer", "LandingBarge", "Loader", "Loiterer", "MAP", "MSP", "MWP", "Neroid", "PSU", "Rhino", "UAV", "Valour", "Vampire", "WhiteRabbit", "WhiteTiger", "XRQ"); $start_frame = 0; $end_frame = 180; @resolution_sizes = ("_1280_960", "_640_480"); $ext = ".png"; ## use CGI; my $query=new CGI; print $query->header; # Print info #my @all=$query->param; #my $name; ##foreach $name (@all) { # print "$name -> ", $query->param($name),"\n"; #} # Make sure filename is allowed $allowed = 0; foreach $i (@allowed_file_list) { for ($j = $start_frame; $j <= $end_frame; $j++) { foreach $k (@resolution_sizes) { $l = sprintf ("%0.5d",$j); $allowed = 1 if $query->param('file') eq "$i$l$k$ext"; } } } if (!$allowed) { print "Access denied.\n"; return; } # Upload file my $bytes_so_far = 0; my $buffer = ''; my $filename = $query->param('file'); my $file_size = ''; my $save_file = "$upload_path/$filename"; my $final_location = "$finished_location/$filename"; # Check stuff if (-e "$final_location") { print "$filename exists.\n"; return; } if (-e "$save_file") { unlink "$save_file"; } # Open file if (!open(WRITEFILE,">$save_file")) { print "Can not open $save_file.\n"; return; } # Save file print "Saving file"; my $right_now=time(); while ($bytes_so_far=read($filename,$buffer,2096)) { $file_size += $bytes_so_far; binmode WRITEFILE; print "."; print WRITEFILE $buffer; } close(WRITEFILE); $right_nower=time()-$right_now; print "\n"; # report if ((stat $save_file)[7] <= 0) { unlink($save_file); print "filename, $file_size bytes took $right_nower seconds, failed to upload.\n"; } else { print "$filename, $file_size bytes took $right_nower seconds, uploaded.\n"; # Move file to finished location system "/bin/mv \"$save_file\" \"$final_location\""; }