Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question