Can I use file_get_contents() to compare two files?

后端 未结 7 1696
无人及你
无人及你 2020-12-03 03:09

I want to synchronize two directories. And I use

file_get_contents($source) === file_get_contents($dest)

to compare two files. Is there an

7条回答
  •  庸人自扰
    2020-12-03 03:58

    Ths will work, but is inherently more inefficient than calculating checksum for both files and comparing these. Good candidates for checksum algorithms are SHA1 and MD5.

    http://php.net/sha1_file

    http://php.net/md5_file

    if (sha1_file($source) == sha1_file($dest)) {
        /* ... */
    }
    

提交回复
热议问题