如果文件扩展名已更改,如何限制文件并尝试使用plupload上载 [英] How to restrict a file if file extension is changed and try to upload using plupload

查看:249
本文介绍了如果文件扩展名已更改,如何限制文件并尝试使用plupload上载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Puploader在java项目中上传文件。我限制一些像.exe这样的文件类型上传。但是当扩展名被更改时,它会被上传。例如,当用户将test.exe文件的扩展名更改为test.txt并尝试上载时,会将其上载到项目中。这会导致我的项目出现严重问题,因为该文件可由其他用户下载。

所以我需要通过检查以前的扩展来限制文件,或者如果可能的话通过检查文件内容来限制文件。有没有办法呢?

如果使用Plupload无法实现,请建议一种在javascript中进行操作的方法。



我尝试了什么:



现在,我使用javascript中的子字符串从文件名中获取扩展名。我需要一种方法来找出原始文件类型,即使扩展名已经改变。

I am using Puploader to upload file in a java project. I am restricting some of the filetypes like .exe from uploading. But when the extension is changed it gets uploaded. For example, when a user changed the extension of the test.exe file to test.txt and tried to upload, its get uploaded in the project. This cause serious issue in my project as the file is downloadable by other users.
So I need to restrict the files by checking the previous extensions or if possible by checking the file content. Is there any way for that?
If not possible by using Plupload, please suggest a way to do it in javascript.

What I have tried:

Now, I fetch the extension from the filename using substring in javascript. I need a way to find out the original filetype even if the extension has changed.

推荐答案

不,没有。

文件扩展名是文件的类型,文件中没有其他签名来提供这些信息。文件扩展名是文件名的一部分,可以随意更改;以前的文件名(包括扩展名更改)不会存储在任何地方,一旦更改名称就无法检索。
No, there isn't.
The file extension is what gives the file it's "type", there is no other "signature"to a file which gives this information. And the file extension is part of the file name and can be changed at will; previous file names (including extension changes) are not stored anywhere and cannot be retrieved once the name is changed.


这篇关于如果文件扩展名已更改,如何限制文件并尝试使用plupload上载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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