4 * Handles HTTP upload of graphics files into the system.
5 * \ingroup WebcitHttpServer
10 void display_graphics_upload(char *description, char *filename, char *uplurl)
15 snprintf(buf, SIZ, "UIMG 0||%s", filename);
17 serv_getln(buf, sizeof buf);
19 strcpy(WC->ImportantMessage, &buf[4]);
23 output_headers(1, 1, 0, 0, 0, 0);
25 output_headers(1, 1, 1, 0, 0, 0);
27 svput("BOXTITLE", WCS_STRING, _("Image upload"));
28 do_template("beginbox");
30 wprintf("<form enctype=\"multipart/form-data\" action=\"%s\" "
31 "method=\"post\" name=\"graphicsupload\">\n", uplurl);
33 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
34 wprintf("<input type=\"hidden\" name=\"which_room\" value=\"");
35 urlescputs(bstr("which_room"));
38 wprintf(_("You can upload an image directly from your computer"));
39 wprintf("<br /><br />\n");
41 wprintf(_("Please select a file to upload:"));
42 wprintf("<input type=\"file\" name=\"filename\" size=\"35\">\n");
44 wprintf("<div class=\"uploadpic\"><img src=\"image&name=%s\"></div>\n", filename);
46 wprintf("<div class=\"buttons\">");
47 wprintf("<input type=\"submit\" name=\"upload_button\" value=\"%s\">\n", _("Upload"));
49 wprintf("<input type=\"reset\" value=\"%s\">\n", _("Reset form"));
51 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
55 do_template("endbox");
60 void do_graphics_upload(char *filename)
67 bytes_remaining = WC->upload_length;
69 if (havebstr("cancel_button")) {
70 strcpy(WC->ImportantMessage,
71 _("Graphics upload has been cancelled."));
76 if (WC->upload_length == 0) {
77 strcpy(WC->ImportantMessage,
78 _("You didn't upload a file."));
83 MimeType = GuessMimeType(&WC->upload[0], bytes_remaining);
84 snprintf(buf, SIZ, "UIMG 1|%s|%s", MimeType, filename);
87 serv_getln(buf, sizeof buf);
89 strcpy(WC->ImportantMessage, &buf[4]);
93 while (bytes_remaining) {
94 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
95 serv_printf("WRIT %d", thisblock);
96 serv_getln(buf, sizeof buf);
98 strcpy(WC->ImportantMessage, &buf[4]);
100 serv_getln(buf, sizeof buf);
104 thisblock = extract_int(&buf[4], 0);
105 serv_write(&WC->upload[pos], thisblock);
106 pos = pos + thisblock;
107 bytes_remaining = bytes_remaining - thisblock;
111 serv_getln(buf, sizeof buf);
113 display_success(&buf[4]);