moved mg_upload() into upload.c