note 85864 added to function.md5-file
| From: | (php.box.md) | Date: | Mon, 22 Sep 2008 08:55:50 +0000 |
| Subject: | note 85864 added to function.md5-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144596@lists.php.net to get a copy of this message | ||
I need to parse a big file after it was changed (a shared XLS file). I've fond a good idea to
check once a minute the checksum of the file, in order to track if it was changed or not. Here is my
code, hope will help some one. Any improvements are welcome!
<?php
$file_xls = "test.xls";
$file_md5 = "test.xls.md5"; // Must exists and must be writable for PHP
$md5_new_file = trim(md5_file($file_xls));
$md5_old_file = trim(file_get_contents($file_md5));
if($md5_new_file <> $md5_old_file)
{
echo "file is out of date, updating now...";
rename($file_md5, $file_md5.".bak");
$fp = fopen($file_md5, 'w');
fwrite($fp, $md5_new_file);
fclose($fp);
/*
Here we do some job...
In my case - dealing with "Spreadsheet Excel Reader"
*/
unlink($file_md5.".bak");
}
// "Not for crontab" - Remove the following section if you are intending to run it in
crontab
else
{
echo "file is up to date, nothing to do...";
}
// End "Not for crontab";
?>
----
Server IP: 89.28.118.75
Probable Submitter: 193.46.212.100
----
Manual Page -- http://www.php.net/manual/en/function.md5-file.php
Edit -- https://master.php.net/note/edit/85864
Del: integrated -- https://master.php.net/note/delete/85864/integrated
Del: useless -- https://master.php.net/note/delete/85864/useless
Del: bad code -- https://master.php.net/note/delete/85864/bad+code
Del: spam -- https://master.php.net/note/delete/85864/spam
Del: non-english -- https://master.php.net/note/delete/85864/non-english
Del: in docs -- https://master.php.net/note/delete/85864/in+docs
Del: other reasons-- https://master.php.net/note/delete/85864
Reject -- https://master.php.net/note/reject/85864
Search -- https://master.php.net/manage/user-notes.php