In mg_upload(), use fopen() with "wb" mode instead of "wbx", cause "x" is not understood by Mac and Windows.