1

i have 2 issue about file input hope that you guys can help .

1- select the text of file input field :

<input type="file" name="userfile" id="userfile" >

usually i do so by using : document.getElementById("userfile").value

but it doesnt work with Files .

2- update field value of file input. same as above , ususally i use :

document.getElementById("userfile").value = 'C:\Users\me\Pictures\pic.jpg';

i want that picture to be the selected value of a file input , but i cant do so . anyhelp please .. ?

2
  • 1
    You can't do that, in any way or form, as the file input has some security restrictions, one of them being that you can't specify files on the users computer to upload. Commented Dec 14, 2013 at 15:07
  • 1
    You can do 1 if the browser already has support for it. You can't do 2. Read up on the HTML5 File API Commented Dec 14, 2013 at 15:10

1 Answer 1

1

As stated, you can't specify a file from JavaScript that points to the user's file system. The browser won't allow you to do so. If this was possible, people would be exposing their files to websites, which could upload their private data without users knowing about it.

For your second question, if you want to access the image that the user has selected, you can use this Bootstrap plugin to get to the image data from a file input once the user has specified a file.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you for help , that's why i could find a way to do so .. :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.