-3

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. Is there any way I can do this without 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>
Ved Tiwari
  • 310
  • 4
  • 12
  • Why don't you want to use PHP? – MARSHMALLOW Apr 10 '20 at 17:44
  • As far as I know, PHP is an internet-based server, meaning you can't use it for offline apps programmed in HTML/JS. Please correct me if I'm wrong – Ved Tiwari Apr 10 '20 at 17:45
  • 2
    You can convert the uploaded image file to a base64 string ([here is an example](https://stackoverflow.com/q/6978156/1552587)) and then save that string to `localStorage` – Titus Apr 10 '20 at 17:49
  • please, accept the answer so that everybody knows it is right – Giuppox Oct 30 '20 at 09:04

1 Answers1

0

you can use an input tag with type="file" to select a file from your device. But you can't save files in a specified location of a machine using js. What you can do is to make the user download it.

<input type="file">
Giuppox
  • 1,393
  • 9
  • 35