Javatpoint Logo
Javatpoint Logo

PHP string sha1_file() Function

The sha1_file() function is predefined PHP string function. It is used to calculate the SHA-1 hash of a file. It uses he US secure Hash Algorithm 1 and calculate the ha1 hash US secure Hash Algorithm 1.

The hash is a 40 character hexadecimal number.

It returns the calculated SHA-1 hash on success or False on failure.


Parameter Description Required/Optional
File Specify file to be calculated. Required
raw Specify hex or binary output format:
  • TRUE : Raw 20 character binary format.
  • FALSE : Default. 40 character hex number.

Example 1

Save it: "test.txt"

Save it: test.php


    Your filename is:test.txt
    By using sha1_file()    function:a02e266c6f3a8ff0c4250e502828c4ebf179d252

Example 2

Save it: "test.txt"

Save it: "sha1file.txt"

Save it: "index.php"

Save it: "test.php "


 The file is ok.

Note: If "test.txt" has been changed (that is if the SHA-1 hash has been changed):

Next TopicPHP String

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA