Are there any limitations on input type="file" when added via javascript? Are there any security concerns?
Asked
Active
Viewed 47 times
0
-
1No, because JavaScript cannot set the "value" property. All websites driven by template systems like React add `` things to their DOMs. – Pointy Jan 21 '20 at 03:09
-
Thanks @Pointy, But I'm having issues with input type="file" element added via javascript. It's not passing data to next page via POST. Here is the link to the question that I asked https://stackoverflow.com/questions/59832733/input-type-file-data-empty-when-posted It would be great if you can check what I'm doing wrong. – MeetuU Jan 21 '20 at 03:12
-
Right: you **cannot** set the "value" attribute of a "file" ``. You can add the element, but the browser will ignore any attempts to set the value. – Pointy Jan 21 '20 at 03:14
-
@Pointy But I'm not setting value attribute. I'm just adding input type="file" element in DOM via javascript. – MeetuU Jan 21 '20 at 04:07
-
Well then there should be no problem at all; it's a perfectly OK thing to do. You didn't post a single bit of code to help anybody understand the problem, so you probably won't get much help from this question. – Pointy Jan 21 '20 at 04:08
-
@Pointy I've posted my code here https://stackoverflow.com/questions/59832733/input-type-file-data-empty-when-posted But no one is answering. – MeetuU Jan 21 '20 at 04:10
1 Answers
0
I think there's none, security will always be on your server on how you handle those requests after posting it through ajax or form

Qonvex620
- 3,819
- 1
- 8
- 15
-
I'm posting it via Form but it's not passing data. The $_FILES array shows empty. – MeetuU Jan 21 '20 at 03:15
-
-
Yes. I've put it but still no luck. I've posted my code in this question https://stackoverflow.com/questions/59832733/input-type-file-data-empty-when-posted Could you please check what I'm doing wrong? – MeetuU Jan 21 '20 at 03:21
-
-
No. Below is my javascript code `var typ = document.getElementById('panDamType').value; var par = document.getElementById('shwChoos'); var cnt = par.childElementCount; //create elements var elm1 = document.createElement('div'); elm1.setAttribute('class', 'row'); var elm2 = document.createElement('input'); elm2.setAttribute('type', 'file'); elm2.setAttribute('name', 'mtu'); elm2.setAttribute('accept', 'image/*'); elm1.appendChild(elm2); par.appendChild(elm1); par.appendChild(document.createElement('br'));` – MeetuU Jan 21 '20 at 03:59
-