Go to the documentation of this file.00001
00002
00003
00004 #include <stdio.h>
00005 #include <string.h>
00006 #include "mongoose.h"
00007
00008 static int send_index_page(struct mg_connection *conn) {
00009 const char *data;
00010 int data_len, ofs = 0;
00011 char var_name[100], file_name[100];
00012
00013 mg_printf_data(conn, "%s",
00014 "<html><body>Upload example."
00015 "<form method=\"POST\" action=\"/handle_post_request\" "
00016 " enctype=\"multipart/form-data\">"
00017 "<input type=\"file\" name=\"file1\" /> <br/>"
00018 "<input type=\"file\" name=\"file2\" /> <br/>"
00019 "<input type=\"submit\" value=\"Upload\" />"
00020 "</form>");
00021
00022 while ((ofs = mg_parse_multipart(conn->content + ofs, conn->content_len - ofs,
00023 var_name, sizeof(var_name),
00024 file_name, sizeof(file_name),
00025 &data, &data_len)) > 0) {
00026 mg_printf_data(conn, "var: %s, file_name: %s, size: %d bytes<br>",
00027 var_name, file_name, data_len);
00028 }
00029
00030 mg_printf_data(conn, "%s", "</body></html>");
00031
00032 return MG_TRUE;
00033 }
00034
00035 static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
00036 switch (ev) {
00037 case MG_AUTH: return MG_TRUE;
00038 case MG_REQUEST: return send_index_page(conn);
00039 default: return MG_FALSE;
00040 }
00041 }
00042
00043 int main(void) {
00044 struct mg_server *server;
00045
00046
00047 server = mg_create_server(NULL, ev_handler);
00048 mg_set_option(server, "listening_port", "8080");
00049
00050
00051 printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
00052 for (;;) {
00053 mg_poll_server(server, 1000);
00054 }
00055
00056
00057 mg_destroy_server(&server);
00058
00059 return 0;
00060 }