我可以使用 MD5+后缀来自定义唯一 ID 的长度吗?
Can I use MD5+suffix for custom length of Unique ID?
我想用它作为数据名称,比如
// Get the file
$file = open('abc.txt');
// Get MD5 Hash value from the file content
// It should be 32 length and Append 2 more(suffix)
$name = MD5_from_file($file) + 'AZ';
// Rename the file as $name
rename($file, $name)
// Then, the file name like this: 9E107D9D372BB6826BD81D3542A419D6AZ.txt
更简单。使用 sha1_file() 而不是 md5()。你真的不需要后缀,散列值 sha1 被设计为唯一的并且依赖于具体文件。两个文件具有相同哈希值的可能性非常小,并且接近于 0。
<?php
$newName = sha1_file('abc.txt');
rename($file, $newName);
?>
sha1() 的长度为 40 个字符。
我想用它作为数据名称,比如
// Get the file
$file = open('abc.txt');
// Get MD5 Hash value from the file content
// It should be 32 length and Append 2 more(suffix)
$name = MD5_from_file($file) + 'AZ';
// Rename the file as $name
rename($file, $name)
// Then, the file name like this: 9E107D9D372BB6826BD81D3542A419D6AZ.txt
更简单。使用 sha1_file() 而不是 md5()。你真的不需要后缀,散列值 sha1 被设计为唯一的并且依赖于具体文件。两个文件具有相同哈希值的可能性非常小,并且接近于 0。
<?php
$newName = sha1_file('abc.txt');
rename($file, $newName);
?>
sha1() 的长度为 40 个字符。