我试图允许用户通过
PHP网站上传文件.由于所有文件都保存在服务器上的单个文件夹中,因此可以想象(尽管可能性很低)两个不同的用户可以上传两个文件,这些文件虽然不同,但命名完全相同.或者他们可能是完全相同的文件.
在这两种情况下,我都想使用exec(“openssl md5”.$file [‘upload’] [‘tmp_name’])来确定文件上传后的MD5哈希值.然后我将检查数据库中是否有任何相同的MD5哈希,如果找到,我将无法完成上传.
但是,在move_uploaded_file文档中,我发现了这条评论:
Warning: If you save a md5_file hash in a database to keep record of uploaded files, which is usefull to prevent users from uploading the same file twice, be aware that after using move_uploaded_file the md5_file hash changes! And you are unable to find the corresponding hash and delete it in the database, when a file is deleted.
这是真的吗?将tmp目录中的文件移动到永久位置后,它的MD5哈希值是否会发生变化?我不明白为什么会这样.无论如何,还有另一种更好的方法可以确保同一文件不会多次上传到文件系统吗?