MIME 类型的吉他专业文件?
在我的网站上,我希望允许人们上传吉他专业文件。显然这些没有特定的 MIME 类型(我测试过,它给了我“application/octet-stream”)。有没有办法检查并 100% 确定这些文件是吉他专业文件而不是其他文件? 谢谢
on my website I want to allow people to upload guitar pro files. Apparently there is no specific MIME type for these (I tested and it gave me 'application/octet-stream'). Is there a way to check and be 100% sure the files are guitar pro files and not something else?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从上传的文件中读取第一个字节。例如,这就是我在创建类似功能时检查上传文件的方式。
因此,读取第 1 到 19 个字符将得到字符串“FICHIER GUITAR PRO”。这种方法对我来说适用于 gp4 文件。我还用来检查文件扩展名。
但请记住,您无法执行真正的检查来过滤恶意上传,因为伪造第一个字节以及扩展名非常容易。因此,应该始终对所有上传的文件进行一些额外的审核。
Read the first bytes from the uploaded file. For example this is how I used to check uploaded files when I was creating similar functionality.
So reading chars from 1st to 19th would give me string 'FICHIER GUITAR PRO'. This approach worked for me for gp4 files. Also I used to check files extensions.
However keep in mind that there is no real check you can perform in order to filter malicious uploads since faking this first bytes as well as extension is pretty easy. So there should always be some additional moderation of all uploaded files.
您应该解析该文件并查看版本字符串是否正确:
You should parse the file and see if the version string is correct: