How to get full path of selected file on change of input type file using javascript jquery-ajax

0 votes

How to get full path of file while selecting file using <input type=‘file’>

<input type="file" id="fileUpload">
<script type="text/javascript">
function getFilePath(){
     $('input[type=file]').change(function () {
         var filePath=$('#fileUpload').val(); 
     });
}
</script>

but the filePath var contains only name of selected file, not the full path.
Is there any other way to get full path of selected file?

Jun 11, 2020 in Java-Script by kartik
• 37,510 points
66,956 views

2 answers to this question.

0 votes

Hello @kartik,

You can use the following code to get a working local URL for the uploaded file:

<script type="text/javascript">    
    var path = (window.URL || window.webkitURL).createObjectURL(file);
    console.log('path', path);
</script>

Hope this helps!!

For more, It is suggested to become a a good Java programmer by completing a full Java course.

thank you!

answered Jun 11, 2020 by Niroj
• 82,860 points
0 votes

For security reasons browsers do not allow this, i.e. JavaScript in browser has no access to the File System, however using HTML5 File API, only Firefox provides a mozFullPath property, but if you try to get the value it returns an empty string:

$('input[type=file]').change(function () {
    console.log(this.files[0].mozFullPath);
});
answered Dec 16, 2020 by Rajiv
• 8,910 points

Related Questions In Java-Script

0 votes
1 answer

How to reset <input type = “file”> using javascript?

Hello @kartik, You need to wrap <input type = ...READ MORE

answered Sep 18, 2020 in Java-Script by Niroj
• 82,860 points
5,527 views
0 votes
1 answer

How to send data in request body with a GET when using jQuery $.ajax()?

Hello @kartik, Sending the data in your scenario,I ...READ MORE

answered Jun 18, 2020 in Java-Script by Niroj
• 82,860 points
16,937 views
0 votes
2 answers

How to animate a change in backgroundColor using jQuery on mouseover?

You don't need jquery. You can also ...READ MORE

answered Sep 9, 2020 in Java-Script by Eureka
• 160 points
1,406 views
0 votes
1 answer

How to Change the selected value of a drop-down list with jQuery?

Hello @kartik, With hidden field you need to ...READ MORE

answered Sep 9, 2020 in Java-Script by Niroj
• 82,860 points
2,115 views
0 votes
1 answer

How can we Create Multiple Where Clause Query Using Laravel Eloquent?

Hii, You can use Conditions using Array: $users = User::where([ ...READ MORE

answered Mar 30, 2020 in Laravel by Niroj
• 82,860 points
15,700 views
0 votes
1 answer

How to send email using php?

Hello @kartik 1.) Download PHPMailer, open the zip file ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,860 points
892 views
0 votes
1 answer

Where to register Facades & Service Providers in Lumen?

Hello, To register a facade with an alias, ...READ MORE

answered Apr 6, 2020 in Laravel by Niroj
• 82,860 points
3,787 views
0 votes
1 answer