简体   繁体   English

如何在jsp中使用javascript对文件MIME类型进行验证

[英]how to do validation for file MIME type using with javascript in jsp

how to do validation for file MIME type using with javascript in jsp. 如何在jsp中使用javascript对文件MIME类型进行验证。 Kindly suggest on same. 请在同一建议。 Whether we can do in client side validation or server side validation . 我们是否可以在客户端验证或服务器端验证中进行。

Regarding the validation it depends. 关于验证取决于它。 If you allow any user to upload a file then the validation should definately happen server side. 如果允许任何用户上载文件,则验证肯定会在服务器端进行。 If the file upload is done from a CMS where only a couple of trusted users have access then you could also rely on a client-side validation(although I would still go with server side). 如果文件上传是通过仅几个受信任用户可以访问的CMS完成的,则您还可以依靠客户端验证(尽管我仍然会使用服务器端)。

Now, in order to check the uploaded file's MIME type it should be fairly easy. 现在,为了检查上载文件的MIME类型,它应该相当简单。 You can use the following: 您可以使用以下内容:

$fileInfo = finfo_open(FILEINFO_MIME_TYPE);
$fileType = finfo_file($fileInfo, $file);
finfo_close($fileInfo);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM