1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-08-09 03:22:45 +03:00

Alternative to mg_upload (Step 39/?)

This commit is contained in:
bel
2016-02-07 22:57:37 +01:00
parent b151ecc9bc
commit 5facf29f71
2 changed files with 13 additions and 2 deletions

View File

@@ -225,13 +225,24 @@ field_get(const char *key,
} }
int
field_stored(const char *path, void *user_data)
{
struct mg_connection *conn = (struct mg_connection *)user_data;
mg_printf(conn, "stored as %s\r\n\r\n", path);
return 0;
}
int int
FormHandler(struct mg_connection *conn, void *cbdata) FormHandler(struct mg_connection *conn, void *cbdata)
{ {
/* Handler may access the request info using mg_get_request_info */ /* Handler may access the request info using mg_get_request_info */
const struct mg_request_info *req_info = mg_get_request_info(conn); const struct mg_request_info *req_info = mg_get_request_info(conn);
int ret; int ret;
struct mg_form_data_handler fdh = {field_found, field_get, 0}; struct mg_form_data_handler fdh = {field_found, field_get, field_stored, 0};
/* TODO: Checks before calling handle_form_data ? */ /* TODO: Checks before calling handle_form_data ? */
(void)req_info; (void)req_info;

View File

@@ -588,7 +588,7 @@ mg_handle_form_data(struct mg_connection *conn,
if (disposition == FORM_DISPOSITION_STORE) { if (disposition == FORM_DISPOSITION_STORE) {
/* Store the content to a file */ /* Store the content to a file */
FILE *fstore = fopen(path, "wb"); fstore = fopen(path, "wb");
if (fstore != NULL) { if (fstore != NULL) {
size_t towrite, n; size_t towrite, n;