How to check if a file has changed?

后端 未结 5 672
梦毁少年i
梦毁少年i 2020-12-20 02:53

I have an xml file with database information that should be loaded when the script is installed or when the content of the file changes. Can I use md5_file() on the xml file

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-20 03:28

    Perhaps you could use PHP's filemtime() function. Simply put, this function gets file modification time for a specified file.

    This function returns a unix time stamp, so you'll need to save the last known modification time somewhere in order to compare it to the new value.

    $modifiedTs = filemtime($filename);
    if ($modifiedTs != $lastModificationTs){
      echo "$filename was modified!";
    }
    

提交回复
热议问题