繁体   English   中英

如何使用html输入标签从用户获取图像并将其存储在树莓派上的文件夹中

[英]How to get an image from a user and store it in a folder on a raspberry pi using the html input tag

我正在尝试使用Html的input标签从用户那里获取图像并将其存储在Web服务器上,该服务器目前是我的PC,但将来我希望将其传输到我的树莓派上,我不想对于该项目使用SQL Server,我所需要知道的最好是使用HTML或PHP或JavaScript,我如何才能从用户那里获取图像并将其存储在Web服务器上以供以后显示,我目前也正在使用xampp有什么用。

看一下这个问题: 使用PHP创建单文件上传表单的最佳方法是什么?

然后您可以编写一些bash脚本来自动在PC和RPi之间复制文件。 或者,您可以从PC上的RPi挂载磁盘,并直接从html表单存储文件。

<input type="file">元素处使用change事件, change事件, FormData()fetch()XMLHttpRequest()

<input type="file" accepts="image/*">
<script>
var input = document.querySelector("input[type=file]");
input.addEventListener("change", function() {
  var file = this.files[0];
  var data = new FormData();
  data.append("file", file);
  fetch("/path/to/server", {method:"POST", body:data})
  .then(response => response.ok)
  .then(res => console.log(res))
})
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM