简体   繁体   中英

JavaScript Open Dialog to get path and file name

Okay,
I've looked EVERYWHERE and everyone keeps answering this question like we're going to actually "download" a file actively.
I am not downloading a file. I am not Uploading a file. I just want a dialog that allows the user to easily provide the path and filename for entry into a textbox so they don't have to type the whole damn thing manually. don't ask why, or what I'm using it for, I just want to know how to open a simple filesystem dialog. The user browses, types a file name, clicks save, and the text input on the form is populated with the fully qualified path. This is definitely possible (maybe not with javascript, but I've seen countless pages that open up a file browse dialog) so how do I do this?
Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner

You can do this with jQuery:

 $(":file").change(function(){ alert($(":file").val()); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form> <input type="file"> </form>

Not too long ago browsers disabled showing the full path to the file on your local machine due to security reasons.

Otherwise you could write ajax script to submit client's paths to the server without the person knowing.

Check the sample script:

 $('#fileSelector').on('change', function( e ) { $('#value').text( e.target.value ); })
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input id="fileSelector" type="file" /> <div id="value"></div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM