input type =" file"在IE中抓取整个文件路径? [英] input type="file" grabs ENTIRE file path in IE?

查看:70
本文介绍了input type =" file"在IE中抓取整个文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入类型=" file"我用来接受文件上传的字段。

这样可行,但我遇到了文件名属性的问题。


在firefox中,这个:


MyInputField.postedfile.filename


返回文件名...只是文件名。这就是我想要的。


然而,在IE中,这会返回ENTIRE本地用户的文件路径到文件

+文件名。哪个,对大多数应用来说都没用。 (实际上,

看起来像是一个安全问题。)


解析整个文件路径的解决方法是否有解决方法
$ b反斜杠的$ b?我当然可以这样做,但也许有更好的方法来获得最终用户使用IE时的文件名。


-Darrel

I have an input type="file" field that I am using to accept a file upload.
This works, but I''m having problems with the filename property.

In firefox, this:

MyInputField.postedfile.filename

returns the filename...and just the filename. Which is what I want.

In IE, however, this returns the ENTIRE local user''s system path to the file
+ the filename. Which, is pretty useless for most applications. (Actually,
it seems like a security issue.)

Is there a workaround for this short of parsing the entire filepath looking
for backslashes? I can certainly do that, but maybe there is a better way to
grab just the filename when the end-user is using IE.

-Darrel

推荐答案

检查FileInfo类。

Check the FileInfo class.


Darrel,


System.IO.Path.GetFileName(MyInputField.postedfile.filename)


将始终返回文件名和扩展名,无论浏览器是什么? b $ b类型。


Eliyahu


" darrel" <无***** @ hotmail.com>在消息中写道

新闻:Oi ************* @ TK2MSFTNGP12.phx.gbl ...
Darrel,

System.IO.Path.GetFileName (MyInputField.postedfile.filename)

will always return the filename and extension regardless of the browser
type.

Eliyahu

"darrel" <no*****@hotmail.com> wrote in message
news:Oi*************@TK2MSFTNGP12.phx.gbl...
我的输入类型= "文件"我用来接受文件上传的字段。
这有效,但我遇到了文件名属性的问题。

在Firefox中,这个:
MyInputField.postedfile.filename

返回文件名...以及文件名。这就是我想要的。

然而,在IE中,这会将ENTIRE本地用户的系统路径返​​回到
文件+文件名。哪个,对大多数应用来说都没用。 (实际上,这似乎是一个安全问题。)

是否有解决方法解决整个文件路径
寻找反斜杠的问题?我当然可以这样做,但也许有更好的方法
在最终用户使用IE时只获取文件名。

-Darrel
I have an input type="file" field that I am using to accept a file upload.
This works, but I''m having problems with the filename property.

In firefox, this:

MyInputField.postedfile.filename

returns the filename...and just the filename. Which is what I want.

In IE, however, this returns the ENTIRE local user''s system path to the file + the filename. Which, is pretty useless for most applications. (Actually,
it seems like a security issue.)

Is there a workaround for this short of parsing the entire filepath looking for backslashes? I can certainly do that, but maybe there is a better way to grab just the filename when the end-user is using IE.

-Darrel



System.IO.Path.GetFileName(string);


-

HTH,


Kevin Spencer

微软MVP

..Net开发人员

你所寻求的是你得到的。


darrel <无***** @ hotmail.com>在消息中写道

新闻:Oi ************* @ TK2MSFTNGP12.phx.gbl ...
System.IO.Path.GetFileName(string);

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"darrel" <no*****@hotmail.com> wrote in message
news:Oi*************@TK2MSFTNGP12.phx.gbl...
我的输入类型= "文件"我用来接受文件上传的字段。
这有效,但我遇到了文件名属性的问题。

在Firefox中,这个:
MyInputField.postedfile.filename

返回文件名...以及文件名。这就是我想要的。

然而,在IE中,这会将ENTIRE本地用户的系统路径返​​回到
文件
+文件名。哪个,对大多数应用来说都没用。 (实际上,这似乎是一个安全问题。)

是否有解决整个文件路径的简短解决方法
寻找反斜杠?我当然可以这样做,但也许有更好的方法
在最终用户使用IE时只获取文件名。

-Darrel
I have an input type="file" field that I am using to accept a file upload.
This works, but I''m having problems with the filename property.

In firefox, this:

MyInputField.postedfile.filename

returns the filename...and just the filename. Which is what I want.

In IE, however, this returns the ENTIRE local user''s system path to the
file
+ the filename. Which, is pretty useless for most applications. (Actually,
it seems like a security issue.)

Is there a workaround for this short of parsing the entire filepath
looking
for backslashes? I can certainly do that, but maybe there is a better way
to
grab just the filename when the end-user is using IE.

-Darrel



这篇关于input type =&quot; file&quot;在IE中抓取整个文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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