#include "Web_Server.h" #include #include #include "SD_Card.h" #include "Display_PNG.h" #include "Audio_Player.h" WebServer server(80); File uploadFile; const char* uploadPage = R"rawliteral( Photo Upload Panel

Upload Photo / Audio

No file selected
Supports PNG (172x320 max) and MP3/WAV.
)rawliteral"; void handleUpload() { HTTPUpload& upload = server.upload(); if (upload.status == UPLOAD_FILE_START) { String filename = upload.filename; if (!filename.startsWith("/")) { filename = "/" + filename; } printf("WebUpload: Starting upload of %s\r\n", filename.c_str()); uploadFile = SD_MMC.open(filename, "w"); } else if (upload.status == UPLOAD_FILE_WRITE) { if (uploadFile) { uploadFile.write(upload.buf, upload.currentSize); } } else if (upload.status == UPLOAD_FILE_END) { if (uploadFile) { uploadFile.close(); printf("WebUpload: Successfully uploaded %s (%d bytes)\r\n", upload.filename.c_str(), upload.totalSize); // Re-scan SD card folders to index the new file Search_Images("/"); Search_Audio("/"); } } } void initWebServer() { // Start WiFi Access Point with SSID "love" and password "love" WiFi.softAP("love", "love"); IPAddress IP = WiFi.softAPIP(); printf("WiFi AP Started. SSID: 'love'\r\n"); printf("Web Server IP address: %s\r\n", IP.toString().c_str()); // Serve Page server.on("/", HTTP_GET, []() { server.send(200, "text/html", uploadPage); }); // Handle file uploads server.on("/upload", HTTP_POST, []() { // Redirect back to main upload page on success server.sendHeader("Location", "/"); server.send(303); }, handleUpload); server.begin(); } void handleWebServer() { server.handleClient(); }