简体   繁体   中英

Why is the md5 returning same hashes for two different file names

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.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM