防止在输入类型=文件中粘贴文件名 [英] Prevent a Paste of a Filename in an Input Type=File

查看:76
本文介绍了防止在输入类型=文件中粘贴文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很少使用crosspost,但这会影响ASP和Javascript


我在ASP 3.0中遇到的奇怪错误。我有一个输入类型

文件,用户点击浏览,然后将光标放在文件名中,将

放在文件末尾的空格中,然后上传它。 Web服务器没有
正确翻译文档的MIME类型,因为它没有以有效的扩展名结束

,但文件本身上传成功。我是

使用SAFileUP作为我的上传组件。


所以我现在在ONKEYPRESS事件中返回一个FALSE,这会阻止

用户进入文件末尾的空格(为什么他这样做是超出我的b $ b,但我正试图用这个东西来证明这一点)。


问题是,ONKEYPRESS并没有阻止字符串粘贴到字段中,因此在技术上仍然可以使用文件名。

模糊焦点控制或将其设置为禁用无法工作

因为它使浏览按钮无法正常工作。


平台: ie6。


任何想法?

I rarely crosspost, but this affects both ASP and Javascript

REALLY odd bug that I ran across in ASP 3.0. I have an input type of
file, user clicks browse, then places his cursor in the filename, puts
a space at the end of the file, and uploads it. Web server doesn''t
translate the MIME type of document properly because it doesn''t end
with a valid extension, yet the file itself uploads successfully. I''m
using SAFileUP for my uploading component.

So I now return a FALSE in an ONKEYPRESS event, which prevents the
user from entering a space at the end of the file (why he does this is
beyond me, but I''m trying to idiot proof this thing).

Problem is, the ONKEYPRESS doesn''t prevent a Paste of a string into
the field, so it''s still technically possible to munge the filename.
Blurring the control on a focus or setting it to disabled doesn''t work
because it makes the Browse button unfunctional.

Platform: i.e.6.

Any ideas?

推荐答案

2月8日,12:23下午,拉里巴德 < larrybud2 ... @ yahoo.comwrote:
On Feb 8, 12:23 pm, "Larry Bud" <larrybud2...@yahoo.comwrote:

我很少使用crosspost,但这会影响ASP和Javascript


我在ASP 3.0中遇到过的奇怪的错误。我有一个输入类型

文件,用户点击浏览,然后将光标放在文件名中,将

放在文件末尾的空格中,然后上传它。 Web服务器没有
正确翻译文档的MIME类型,因为它没有以有效的扩展名结束

,但文件本身上传成功。我是

使用SAFileUP作为我的上传组件。


所以我现在在ONKEYPRESS事件中返回一个FALSE,这会阻止

用户进入文件末尾的空格(为什么他这样做是超出我的b $ b,但我正试图用这个东西来证明这一点)。


问题是,ONKEYPRESS并没有阻止字符串粘贴到字段中,因此在技术上仍然可以使用文件名。

模糊焦点控制或将其设置为禁用无法工作

因为它使浏览按钮无法正常工作。


平台: ie6。


有什么想法吗?
I rarely crosspost, but this affects both ASP and Javascript

REALLY odd bug that I ran across in ASP 3.0. I have an input type of
file, user clicks browse, then places his cursor in the filename, puts
a space at the end of the file, and uploads it. Web server doesn''t
translate the MIME type of document properly because it doesn''t end
with a valid extension, yet the file itself uploads successfully. I''m
using SAFileUP for my uploading component.

So I now return a FALSE in an ONKEYPRESS event, which prevents the
user from entering a space at the end of the file (why he does this is
beyond me, but I''m trying to idiot proof this thing).

Problem is, the ONKEYPRESS doesn''t prevent a Paste of a string into
the field, so it''s still technically possible to munge the filename.
Blurring the control on a focus or setting it to disabled doesn''t work
because it makes the Browse button unfunctional.

Platform: i.e.6.

Any ideas?



不要试图用Javascript中的文件上传输入字段做任何事情,它可能不起作用(只需使用VB服务器端代码修剪)你得到的文件名是

中的空格。)


因为恶意JS可以上传它想要的任何文件,只需通过

在文件上传字段中查看路径,

在JS中我无法更改.value我相信有限制

关键事件也可以做什么。

DONT try to do anything wih file upload input field in Javascript,it
may not work (Just Use VB server side code to trim out the spaces in
the filename you get. )

since a malicious JS can upload whatever files it wants, just by
chaning the path in the File upload field,
one cannot change .value on it in JS an i belive there are constraints
on what can be done with key events too.


2月8日下午12:32,dev_jg < develope ... @ gmail.comwrote:
On Feb 8, 12:32 pm, "dev_jg" <develope...@gmail.comwrote:

2月8日下午12:23,Larry Bud < larrybud2 ... @ yahoo.comwrote:

On Feb 8, 12:23 pm, "Larry Bud" <larrybud2...@yahoo.comwrote:



我很少交叉,但这会影响ASP和Javascript
I rarely crosspost, but this affects both ASP and Javascript


我在ASP 3.0中遇到过的奇怪错误。我有一个输入类型

文件,用户点击浏览,然后将光标放在文件名中,将

放在文件末尾的空格中,然后上传它。 Web服务器没有
正确翻译文档的MIME类型,因为它没有以有效的扩展名结束

,但文件本身上传成功。我是使用SAFileUP上传组件的

REALLY odd bug that I ran across in ASP 3.0. I have an input type of
file, user clicks browse, then places his cursor in the filename, puts
a space at the end of the file, and uploads it. Web server doesn''t
translate the MIME type of document properly because it doesn''t end
with a valid extension, yet the file itself uploads successfully. I''m
using SAFileUP for my uploading component.


所以我现在在ONKEYPRESS事件中返回一个FALSE,这会阻止

用户在最后输入一个空格该文件(为什么他这样做是超出我的b $ b,但我正试图用这个东西证明这一点)。
So I now return a FALSE in an ONKEYPRESS event, which prevents the
user from entering a space at the end of the file (why he does this is
beyond me, but I''m trying to idiot proof this thing).


问题是,ONKEYPRESS并没有阻止字符串粘贴到字段中,所以它'在技​​术上仍然可以使用文件名。

模糊焦点控制或将其设置为禁用无法工作

因为它使浏览按钮无法正常工作。
Problem is, the ONKEYPRESS doesn''t prevent a Paste of a string into
the field, so it''s still technically possible to munge the filename.
Blurring the control on a focus or setting it to disabled doesn''t work
because it makes the Browse button unfunctional.


平台:即6。
Platform: i.e.6.


有什么想法吗?
Any ideas?



不要尝试用Javascript中的文件上传输入字段做任何事情,它可能不起作用(只需使用VB服务器端代码修剪)你得到的文件名是

中的空格。)


因为恶意JS可以上传它想要的任何文件,只需通过

在文件上传字段中查看路径,

在JS中我无法更改.value我相信有限制

关键事件也可以做什么.-隐藏引用的文字 -


- 显示引用的文字 -


DONT try to do anything wih file upload input field in Javascript,it
may not work (Just Use VB server side code to trim out the spaces in
the filename you get. )

since a malicious JS can upload whatever files it wants, just by
chaning the path in the File upload field,
one cannot change .value on it in JS an i belive there are constraints
on what can be done with key events too.- Hide quoted text -

- Show quoted text -



对于previos回复感到抱歉,你不能在我说的方式,


i忘记你只是在ASP端得到文件流而不是

文件名。

sorry about the previos reply, you cant implement in the way i said,

i forgot that you just get the file stream on ASP end and not the
fileName.


输入字段是**只读** **。那你可以看,但是你不能以任何方式修改内容或改变行为。什么

你可以做的是在你的表格中做一个onSubmit事件并检查文件

名称,如果有什么你不喜欢它(尾随空格)对于

实例)你可以提醒用户并禁止提交。


这是你能想到的最好的。抱歉。



Larry Bud写道:
input fields are **READ ONLY** by javascript. That is you can look but
you can not in any way modify the contents or alter the behavior. What
you can do is to do an onSubmit event in your form and check the file
name, if there is anything you don''t like about it (trailing spaces for
instance) you can alert the user and disallow the submission.

That''s the best you can hope for. Sorry.


Larry Bud wrote:

我很少交叉,但这会影响ASP和Javascript


我在ASP 3.0中遇到过的奇怪错误。我有一个输入类型

文件,用户点击浏览,然后将光标放在文件名中,将

放在文件末尾的空格中,然后上传它。 Web服务器没有
正确翻译文档的MIME类型,因为它没有以有效的扩展名结束

,但文件本身上传成功。我是

使用SAFileUP作为我的上传组件。


所以我现在在ONKEYPRESS事件中返回一个FALSE,这会阻止

用户进入文件末尾的空格(为什么他这样做是超出我的b $ b,但我正试图用这个东西来证明这一点)。


问题是,ONKEYPRESS并没有阻止字符串粘贴到字段中,因此在技术上仍然可以使用文件名。

模糊焦点控制或将其设置为禁用无法工作

因为它使浏览按钮无法正常工作。


平台: ie6。


任何想法?
I rarely crosspost, but this affects both ASP and Javascript

REALLY odd bug that I ran across in ASP 3.0. I have an input type of
file, user clicks browse, then places his cursor in the filename, puts
a space at the end of the file, and uploads it. Web server doesn''t
translate the MIME type of document properly because it doesn''t end
with a valid extension, yet the file itself uploads successfully. I''m
using SAFileUP for my uploading component.

So I now return a FALSE in an ONKEYPRESS event, which prevents the
user from entering a space at the end of the file (why he does this is
beyond me, but I''m trying to idiot proof this thing).

Problem is, the ONKEYPRESS doesn''t prevent a Paste of a string into
the field, so it''s still technically possible to munge the filename.
Blurring the control on a focus or setting it to disabled doesn''t work
because it makes the Browse button unfunctional.

Platform: i.e.6.

Any ideas?



-
http://www.hunlock.com - Javascript,CSS中的冥想。


--
http://www.hunlock.com -- Musings in Javascript, CSS.


这篇关于防止在输入类型=文件中粘贴文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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