Handling interrupted file uploads

There are occasionally problems involving parsing the uploaded file. This usually happens when the user presses “Stop” before the upload is finished. In this case, CGI.pm will return undef for the name of the uploaded file and set cgi_error() to the string “400 Bad request (malformed multipart POST)”. This error message is designed so that you can incorporate it into a status code to be sent to the browser. Example:

$file = $q->upload(‘uploaded_file’);
if (!$file && $q->cgi_error) {
print $q->header(-status=>$q->cgi_error);
exit 0;
}

You are free to create a custom HTML page to complain about the error, if you wish.