admin管理员组文章数量:1279090
I face the following problem:
When a user uploads a file with the HTML file input and I then want to receive the file path itself. I only get C:/fakepath/filename.txt
for example.
I understand that it is a security reason for browsers to know the exact path of the file. So i was wondering if it is even possible with some hack, some way in or with additional jquery/js plugin to get the full path of the file.
Why?
We dont want to upload the file itself to our server filesystem, neither to the database. We just want to store the local path in the database so when the same user opens the site, he can click on that path and his local file system opens.
Any suggestions or remendations for this approach?
If this is really not possible like
How to resolve the C:\fakepath?
How To Get Real Path Of A File Using Jquery
we would need to e up with a diffrent idea I guess. But since some of the answers are really old, I thought maybe there is a solution to it by now. Thx everyone
I face the following problem:
When a user uploads a file with the HTML file input and I then want to receive the file path itself. I only get C:/fakepath/filename.txt
for example.
I understand that it is a security reason for browsers to know the exact path of the file. So i was wondering if it is even possible with some hack, some way in or with additional jquery/js plugin to get the full path of the file.
Why?
We dont want to upload the file itself to our server filesystem, neither to the database. We just want to store the local path in the database so when the same user opens the site, he can click on that path and his local file system opens.
Any suggestions or remendations for this approach?
If this is really not possible like
How to resolve the C:\fakepath?
How To Get Real Path Of A File Using Jquery
we would need to e up with a diffrent idea I guess. But since some of the answers are really old, I thought maybe there is a solution to it by now. Thx everyone
Share Improve this question edited May 23, 2018 at 9:20 G43beli asked May 23, 2018 at 9:11 G43beliG43beli 3,9724 gold badges24 silver badges29 bronze badges 8- 4 What's the benefit of a security feature you can hack? – Teemu Commented May 23, 2018 at 9:22
- Would you want other websites to be able to do this? – Máté Safranka Commented May 23, 2018 at 9:22
- @Teemu I thought maybe reading just exact this path would be possible with a browser. Not having access to the filesystem itself. Because for example IE is showing the real path in the input field. But you can not access it – G43beli Commented May 23, 2018 at 9:27
- The security feature here is to hide the pathname ... Use IE with file protocol if you want to get the real path. – Teemu Commented May 23, 2018 at 9:32
- 1 Possible duplicate of How to get full path of selected file on change of <input type=‘file’> using javascript, jquery-ajax? – symcbean Commented May 23, 2018 at 9:54
3 Answers
Reset to default 2You can't do it.
And if you find a way, it's big security vulnerability that the browser manufacturer will fix when discovered.
As my goal was to make the uploaded file name visible to the End User and then send it via php mail() function, All I did to resolve this was:
in your js file
Old function:
var fileuploadinit = function(){
$('#career_resume').change(function(){
var pathwithfilename = $('#career_resume').val();
$('.uploadedfile').html("Uploaded File Name :" + pathwithfilename).css({
'display':'block'
});
});
};
Corrected function:
var fileuploadinit = function(){
$('#career_resume').change(function(){
var pathwithfilename = $('#career_resume').val();
var filename = pathwithfilename.substring(12);
$('.uploadedfile').html("Uploaded File Name :" + filename).css({
'display':'block'
});
});
};
$(document).ready(function () {
fileuploadinit();
});
Old result:
Uploaded File Name :C:\fakepath\Coverpage.pdf
New result:
Uploaded File Name :Coverpage.pdf
Hope it helps :)
You'll need your own code running outside browser-box to do this, since browsers are designed NOT to allow this.
I mean something ugly like ActiveX, flash, COM object, custom browser extenstion or other fancy security breach that can open it's own OpenFileDialog and insert that value in your input field.
本文标签: javascriptGet real path instead of 39fakepath39 in file uploadStack Overflow
版权声明:本文标题:javascript - Get real path instead of 'fakepath' in file upload - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741232042a2362287.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论