Reputation: 17
I have two video file having different file names.But when I md5 filenames both are returning same hashes. Below are the file names.
1.\test\downloadvideo\ans-70055040.hd.mp4
2.\test\downloadvideo\ans-70055298.hd.mp4
$this->_video_md5 = md5_file("\test\downloadvideo\ans-70055040.hd.mp4");
$this->_videoo_md51 = md5_file("\test\downloadvideo\ans-70055298.hd.mp4");
echo "md5".$this->_video_md5
will return md551f767588587184d13b8c9e6ed550166sh190d2078270d4ea1cb570b1de7 fb890bc761bda9a
echo "md5".$this->_videoo_md51
will return md551f767588587184d13b8c9e6ed550166sh190d2078270d4ea1cb570b1de7 fb890bc761bda9a
How can I get two different md5 hashes for the file names.
Upvotes: 0
Views: 2474
Reputation: 11832
To get different hashes, change the contents of the files, so the files are not identical.
If you want to check the filenames only , use md5("filename")
and not md5_file("filename")
Also you don't seem to have quotes around the filename. They should be there! And escape backslashes!
So
md5_file(\test\downloadvideo\ans-70055298.hd.mp4);
should be
md5_file("\\test\\downloadvideo\\ans-70055298.hd.mp4");
otherwise, \t
ist interpreted as a tab character.
Due to that, your md5_file
get's an invalid filename both times, thus returning the same hash.
Upvotes: 1
Reputation: 1856
Use md5("\test\downloadvideo\ans-70055298.hd.mp4");
instead of md5_file, if you want to hash the filename, not the contents of the file.
Upvotes: 1
Reputation: 471
As written above, md5|sha1_file
return the hash of the file contents, not including the file's name.
A possible "solution" would be to hash the outcome of both the filename and the hash of the file itself, which will be a unique hash again.
Upvotes: 2