chrome中没有提供FileUpload.PostedFile.FileName的完整路径 [英] FileUpload.PostedFile.FileName not giving full path in chrome

查看:225
本文介绍了chrome中没有提供FileUpload.PostedFile.FileName的完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我在网站上使用文件上传控件.我要从上传文件的位置获取该文件的完整路径.
我用.

Hi I am using File Upload control in my web site. I want full path of that file from Where I am uploading that file.
I use.

string path = Server.MapPath(FileUpload1.PostedFile.FileName);



但是给我我保存该文件的路径,而不是我选择该文件的路径....

我希望您能理解我的问题.



But giving me the path where I am saving that file and not the path from where i m picking that file....

I hope u understand my problem.

推荐答案

Server.MapPath将映射到服务器的路径.

所以,

Server.MapPath will map to the Server''s path.

So,

string path = Server.MapPath(FileUpload1.PostedFile.FileName);



不正确.

这将帮助您解决问题文件上传丢失目录路径. [ ^ ]

我认为获取上传器文件位置没有用.



is not correct.

And this would help you to solve your problem FileUpload loses directory path.[^]

I see no use in getting the uploader file location.


string path = FileUpload1.PostedFile.FileName;



请参见此处 [ ^ ]



See here[^]


让我逐步向您解释一下.
Let me explain it to you step by step.
FileUpload1.PostedFile.FileName


实际上,这为您提供了上载文件的路径.

但由于安全原因,在所有较新的浏览器(FF 3.6系列,Chrome,IE7 +)中,此功能已被禁用.任何网站都不需要存储在客户端系统中的文件的路径,因为它提供了目录结构,并且可能向网站所有者公开其他重要内容.

因此,在您的情况下,以上代码仅返回文件名.

现在,当您将Server.MapPath添加到文件名时,它将其映射到服务器上相应的物理目录.因此,它为您提供了服务器路径.

希望可以弄清楚.


This actually gives you path of the uploaded file.

But in all the newer browsers (FF 3.6 series, Chrome, IE7+) this feature has been disabled due to security reasons. Any website should not need path of a file stored in client''s systems because that gives the directory structure and may expose other important things to website owner.

So in your case, the above code returned only the file name.

Now when you added Server.MapPath to the file name, it maps it to the corresponding physical directory on the server. So it is giving you a server path.

Hope that makes it clear.


这篇关于chrome中没有提供FileUpload.PostedFile.FileName的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆