What would you say are the essential steps in verifying a file upload?
I'd tend to check the MIME type, give it a new (random) name, make sure its got an allowed file extension, and then I'd check the contents of the file. How do you go about it?
What would you say are the essential steps in verifying a file upload?
I'd tend to check the MIME type, give it a new (random) name, make sure its got an allowed file extension, and then I'd check the contents of the file. How do you go about it?
检查(按此顺序):文件 MIME 类型(并注意某些浏览器存在 MIME 类型检测问题...);文件路径存在;不存在具有相同名称的文件的先前版本,否则,请修改它;文件不是太大;成功后,在服务器上运行病毒检查。
Check the file type, check the file size, the image dimension.
These are the 3 I always check to be sure to have good result.
取决于预期的文件内容...对文件运行病毒扫描可能是个好主意。
例如,如果您收到个人资料照片的 gif 文件,则应检查 mime 类型是否为 gif。
这样您就可以避免上传坏文件。
这里有一个使用 php 的示例。