I trying to create an array of filename hashes (key) and filenames (value), but most functions I use don’t seem to work like I want them to…
Why are these functions when used in a loop resulting in the same output string while the input string varies? md5 and sha1 don’t have this problem, but aren’t reversible and that’s needed.
foreach ($files as $file)
{
debug(array(bin2hex($file), $file));
}
// result
app/views/helpers/monolith.php (line 45)
Array
(
[0] => 2f686f6d652f6d746572736d697474656e2f7075626c69635f68746d6c2f6170702f707269766174652f6d622f323031302f31322e706466
[1] => /home/mtersmitten/public_html/app/private/mb/2010/12.pdf
)
app/views/helpers/monolith.php (line 45)
Array
(
[0] => 2f686f6d652f6d746572736d697474656e2f7075626c69635f68746d6c2f6170702f707269766174652f6d622f323031302f31312e706466
[1] => /home/mtersmitten/public_html/app/private/mb/2010/11.pdf
)
app/views/helpers/monolith.php (line 45)
Array
(
[0] => 2f686f6d652f6d746572736d697474656e2f7075626c69635f68746d6c2f6170702f707269766174652f6d622f323031302f31302e706466
[1] => /home/mtersmitten/public_html/app/private/mb/2010/10.pdf
)
I hope this example is more clear…
In fact the strings are different. You should check more carefully. They are the same for the most part, because both bin2hex and base64_encode encode the sequence of bytes and do not generate a hash like sha1 or md5.
bin2hex just converts every character in the string to its hex value and as for base64, check the wikipedia article to see exactly why the string is the same for large part of the outcome