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.

Syntax:

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.
Optional

Example 1

Save it: "test.txt"

Save it: test.php

Output:

    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 "

Output:

 The file is ok.

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


Next TopicPHP String




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA