使用 PHP 上传音频文件
我需要建立一个允许注册用户上传音频文件的网站。 我想知道是否有关于安全的防弹实践。 该网站是用 PHP 构建的
I need to make a website that will allow registered users to upload audio files.
I wonder is there any bullet proof practice regarding security.
The site is built in PHP
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
检查上传文件的 mime 类型
更多信息请参见:http://www.w3schools.com/media/media_mimeref。 ASP
Check mime type of uploading file
More here: http://www.w3schools.com/media/media_mimeref.asp
您需要仔细检查文件类型。这意味着不只是在文件名上执行子字符串来获取扩展名。扩展名并不是文件实际内容的具体指示。
正如 Danzan 所说,您需要使用如下代码来检查文件的 MIME 类型:
这可以将用户将恶意 PHP 代码上传到您的上传目录的机会基本上降低到零。
You will want to check the file type carefully. This means not just doing a substring on the file name to get the extension. The extension is not a concrete indicator of what the file actually is.
As Danzan said, you will want to check the MIME type of the file, using some code like this:
This reduces the chances of a user uploading, say, malicious PHP code into your upload directory to basically zero.
通过 getimagesize、fileinfo 扩展和 mime_content_type 函数的组合提供防弹文件类型检查(Nette Framework 属性):
您不能信任来自客户端的任何数据,因为它们很容易被伪造。
Bullet-proof file type check is provided via combination of getimagesize, fileinfo extension and mime_content_type function (Nette Framework property):
You can not trust any data coming from the client, because they can be easily forged.
您可以使用 PHP 上传任何内容。这是一个示例: http://www.tizag.com/phpT/fileupload.php
关于安全性,您必须验证是否只允许某些人上传内容,并且您验证他们上传的内容(文件大小、文件类型等)。
You can upload anything with PHP. Here's an example: http://www.tizag.com/phpT/fileupload.php
Regarding security, you have to verify that only certain people are allowed to upload stuff and that you verify the contents of what they're uploading (file size, file type, etc).