F
F
Fanil Ganeev2020-11-08 08:37:23
Images
Fanil Ganeev, 2020-11-08 08:37:23

How to add images from local disk to js via input?

Good afternoon, I'm just learning, I can't figure out how to assign a local link to the js array, which will contain a link to img, the console gives fakepath, that is, like this C:\fakepath\202005144454fc6.jpg, please tell me what am I doing wrong? here is an example:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="file" name="" id="imgFiles" />
    <button onclick="fun1()" id="btn">Добавить</button>
    <script src="main.js"></script>
  </body>
</html>

const imgFiles = document.getElementById('imgFiles')
const btn = document.getElementById('btn')

function fun1() {
    const photoDB = {
        photo: []
    }
    photoDB.photo[0] = imgFiles.value
    console.log(photoDB.photo)
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2020-11-08
@firedragon

This is the browser's security system, so you won't know the path, just the filename.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question