0

i would give value to a input file with javascript.

I writed this :

<input type="file" name="okuludf[]" id="resimeklec2" class="resimeklec2" multiple="multiple">//HTML
document.getElementById("resimeklec2").value = "<?php echo($_SESSION['yol2']); ?>";//JS

This code is in the script tag.

But the code doesn't work.

How can i resolve this problem?

I need your help.

Veli Kurt
  • 13
  • 5
  • I'm not sure, what the problem is here. It may be with the PHP, it may be with the JS. If you `console.log("");` Does that work? Are you getting the correct log in the console? – Syntac Dec 09 '17 at 18:23
  • @Syntac yes no problem in yol2 – Veli Kurt Dec 09 '17 at 18:27
  • @Syntac i give this error : **Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.** – Veli Kurt Dec 09 '17 at 18:28
  • @Syntac yol2 : uploads/Ekran Görüntüsü (276).png – Veli Kurt Dec 09 '17 at 18:29
  • okay, I see. The problem is, that as a safety measure, it won't let you set `document.getElementById("resimeklec2").value` via js. I believe, it won't accept it as an HTML attribute either. – Syntac Dec 09 '17 at 18:30
  • https://stackoverflow.com/questions/1696877/how-to-set-a-value-to-a-file-input-in-html#1696884 look here. Sorry, but seems, like it isn't possible. – Syntac Dec 09 '17 at 18:31
  • You cannot do this, the user must choose the file otherwise your effectively giving unrestricted access to a users file system. – Alex K. Dec 09 '17 at 18:31

0 Answers0