我有一个简单的服务器在ESP8266上运行,SD卡上有文件 . 在我的电脑上,我正在运行wampserver,并有一个页面将文件上传到ESP上的SD卡'
<!DOCTYPE html>
<html>
<head>
<title>Handle Files</title>
<h1 style="text-align:center;">
File access page</h1>
</head>
<body>
<form action="http://192.168.1.8/upload" method="post"
enctype="multipart/form-data">
<input type="text" name="ip" value="192.168.1.8">
<input type="file" name="name">
<input class="button" type="submit" value="Upload">
</form>
</body>
</html>
我可以通过两种方式连接到ESP - 作为接入点和WiFi . 当作为接入点连接时,IP为192.168.4.1,而当WiFi为192.168.1.8时 .
如何在表单的操作中使用名为ip的文本框中的IP地址 .
我假设我需要javascript,并且已经使用它广泛地将各种数据从服务器传回到其他页面,但这包括我 .
请注意,服务器会将重定向发送回同一页面 .
麦克风 . 编辑,这是处理上传的服务器端代码 .
void handleUpload(){
static File in;
HTTPUpload& upload = server.upload();
if(upload.status == UPLOAD_FILE_START){
String filename = upload.filename;
if(!filename.startsWith("/")) filename = "/"+filename;
Serial.print("handleUpload Name: ");
Serial.println(filename);
if(SD.exists(filename))
SD.remove(filename);
in = SD.open(filename,FILE_WRITE); // Open the file for writing
}else if(upload.status == UPLOAD_FILE_WRITE){
if(in)
in.write(upload.buf, upload.currentSize); // Write the received bytes to the file
}else if(upload.status == UPLOAD_FILE_END){
if(in) { // If the file was successfully created
in.close(); // Close the file again
Serial.print("handleUpload Size: ");
Serial.println(upload.totalSize);
server.sendHeader("Location","http://localhost/file.htm"); // Redirect the client back to local
server.send(303);
}else{
server.send(500, "text/plain", "500: couldn't create file");
}
}
}