RE: [PHP] Comparing files
| From: | mathieu leddet | Date: | Wed, 12 Mar 2008 11:34:26 +0000 |
| Subject: | RE: [PHP] Comparing files | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-271344@lists.php.net to get a copy of this message | ||
Yes!
Thanks a lot, "md5_file" suits perfectly well my needs.
I've read that 'exec'ing the md5 command is faster... I'll see when performance
on large files will become an issue.
Thanks again,
--
Mathieu
-----Message d'origine-----
De : Thijs Lensselink [mailto:dev@lenss.nl]
Envoyé : Wednesday, March 12, 2008 12:09 PM
À : php-general@lists.php.net
Objet : Re: [PHP] Comparing files
Quoting mathieu leddet <mathieu.leddet@mobilescope.com>:
> Hi all,
>
> I have a simple question : how can I ensure that 2 files are identical ?
>
> How about this ?
>
> --------8<------------------------------------------------------
>
> function files_identical($path1, $path2) {
>
> return (file_get_contents($path1) == file_get_contents($path2));
>
> }
>
> --------8<------------------------------------------------------
>
> Note that I would like to compare any type of files (text and binary).
>
> Thanks for any help,
>
>
> --
> Mathieu
>
You could use "md5_file" for this. Something like:
function files_identical($path1, $path2) {
return (md5_file($path1) == md5_file($path2));
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php