esp32 post multipart/form-data: Undefined index error
Posted: Thu May 07, 2020 5:55 pm
i've been trying to POST an SPIFFS file from esp32 to my local server..
but i cannot succeed...
i have seen numerous other posts doing multipart POST and compare to my code, and i cannot find any problem..(i use the info here)
(of course i have tested simple connections (some GET etc..and everything looks to work)
this is my esp32 code:
my save_File.php is like example 2 here
But i receive:
any idea?
but i cannot succeed...
i have seen numerous other posts doing multipart POST and compare to my code, and i cannot find any problem..(i use the info here)
(of course i have tested simple connections (some GET etc..and everything looks to work)
this is my esp32 code:
Code: Select all
...
const char* localhost = "192.168.1.X";
writeFile(SPIFFS, "/001.txt", "this is a test");
file = SPIFFS.open("/001.txt");
int myFileSizeInt = file.size();
String myFileSizeStr = (String)myFileSizeInt;
client.print(String("POST ") + "/save_File.php" +" HTTP/1.1\r\n" +
"Host: " + localhost + "\r\n" +
"Content-Type: multipart/form-data;boundary=boundary\r\n" +
"Content-Length: " + myFileSizeStr + "\r\n\r\n" +
"--boundary\r\n" +
"Content-Disposition: form-data; name=\"userfile\"; filename=\"001.txt\"\r\n" +
"Content-Type: text/plain\r\n\r\n");
while (file.available()) {
char c = file.read();
client.print(c);
}
client.print("\r\n--boundary--\r\n");
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("headers received");
break;
}
}
Serial.println("localhost response");
while (client.available()) {
char c = client.read();
Serial.write(c);
}
client.stop();
}
But i receive:
Code: Select all
Undefined index: userfile in <b>myphpFolder..</b> on line <b>7</b><br />
<pre><br />
<b>Notice</b>: Undefined index: userfile in <b>myphpFolder..</b> on line <b>11</b><br />
Possible file upload attack!
Here is some more debugging info:Array
(
)
</pre>HTTP/1.1 400 Bad Request
...