Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I have a preselected input for when type="file"? [duplicate]

Note:

The answers & comments below reflect the state of legacy browsers in 2009. Now you can actually set the value of the file input element dynamically/programatically using JavaScript in 2017.

See the answer in this question for details as well as a demo:
How to set file input value programatically (i.e.: when drag-dropping files)?

How can I setup an <input> tag where when the user submits the form, it will still show the previously selected file?

I've tried the following:

<input type="file" name="upfile" value="<?=isset($_POST['upfile'])?$_POST['upfile']:''?>"/>

but it doesn't seem to work!

like image 243
Arian Faurtosh Avatar asked Oct 24 '25 01:10

Arian Faurtosh


1 Answers

With input type file it isn't possible to set up a default value. You have to use some plugins e.g. http://blueimp.github.io/jQuery-File-Upload/

Read following article How to set a value to a file input in HTML?

like image 85
algorhythm Avatar answered Oct 25 '25 16:10

algorhythm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!