vb.net 在文件上传中获取真实路径而不是“假路径”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50484303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get real path instead of 'fakepath' in file upload
提问by G43beli
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.txtfor example.
当用户上传带有 HTML 文件输入的文件时,我想接收文件路径本身。我只得到C:/fakepath/filename.txt例如。
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 .net or with additional jquery/js plugin to get the full path of the file.
我知道浏览器知道文件的确切路径是出于安全原因。所以我想知道是否有可能通过一些 hack、.net 中的某种方式或附加的 jquery/js 插件来获取文件的完整路径。
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 recommendations 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 come 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
我想我们需要想出一个不同的想法。但是由于一些答案真的很旧,我想现在可能有解决方案。谢谢大家
采纳答案by PavlinII
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.
我的意思是一些丑陋的东西,比如 ActiveX、flash、COM 对象、自定义浏览器扩展或其他花哨的安全漏洞,可以打开它自己的 OpenFileDialog 并在您的输入字段中插入该值。
回答by Terry Carmen
You can't do it.
你不能这样做。
And if you find a way, it's big security vulnerability that the browser manufacturer will fix when discovered.
如果你找到了一种方法,浏览器制造商会在发现时修复一个很大的安全漏洞。
回答by Subhasish Nath
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:
由于我的目标是让上传的文件名对最终用户可见,然后通过 php mail() 函数发送,我所做的就是解决这个问题:
in your js file
在你的 js 文件中
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
上传的文件名:C:\fakepath\Coverpage.pdf
New result:
新结果:
Uploaded File Name :Coverpage.pdf
上传文件名:Coverpage.pdf
Hope it helps :)
希望能帮助到你 :)

