sub upload_file { my ($g, $q, $readpath, $writepath) = @_; my $rfh; if (!open($rfh, "<", $readpath)) { $g->errorpage($q, "Could not open file '$readpath': $!\n"); return 0; } my $wfh; if (!open($wfh, '>', $writepath)) { $g->errorpage($q, "Error creating file '$writepath': $!\n"); return 0; } binmode($rfh); binmode($wfh); while (read($rfh, my $buf, 4*1024)) { print $wfh $buf; } close($wfh); chmod 0600, $writepath; return 1; }