Store the SHA-1 hash of "test.txt" in a file in PHP

Description

The following code shows how to store the SHA-1 hash of "test.txt" in a file.

Example


//from w  ww  . j  a  v  a2s  .co m
<?php
    $sha1file = sha1_file("test.txt");
    file_put_contents("sha1file.txt",$sha1file);
    //Test if "test.txt" has been changed (that is if the SHA-1 hash has been changed):

    $sha1file = file_get_contents("sha1file.txt");
    if (sha1_file("test.txt") == $sha1file){
        echo "The file is ok.";
    }else{
        echo "The file has been changed.";
    }
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    File »




Directory
DirectoryIterator
Drive
File
File Permission
File Read Save
FileSystemIterator
Path
Zip