简体   繁体   English

使用 JavaScript/HTML 上传文件

[英]Upload a file with JavaScript/HTML

I am working on trying to make a prompt where you can upload an image and save it on localStorage, but I couldn't find a way of doing this without PHP, which I don't want to use.我正在尝试提示您可以上传图像并将其保存在 localStorage 上,但如果没有 PHP,我找不到这样做的方法,我不想使用它。 Is there any way I can do this without PHP?如果没有 PHP,我有什么办法可以做到这一点?

 function upload() { //script to display the dialog box and enter the name of the file in the h4 element. }
 <button onclick="upload()">Upload File</button> <h4 id="fileName">No File Selected</h4>

you can use an input tag with type="file" to select a file from your device.您可以使用 type="file" 的输入标签到 select 设备中的文件。 But you can't save files in a specified location of a machine using js.但是不能使用js将文件保存在机器的指定位置。 What you can do is to make the user download it.您可以做的是让用户下载它。

 <input type="file">

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

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