PHP | hash_file( ) Function Last Updated : 29 Oct, 2018 Comments Improve Suggest changes Like Article Like Report The hash_file() function is an inbuilt function in PHP which is used to generate a hash value using the contents of a given file. Syntax: string hash_file( $algo, $file, $raw_opt ) Parameters: This function accept three parameters as mention above and describe below. $algo: It is the required parameter which specifies the selected hashing algorithm. $file: This parameter is used to hold the file url to be hashed. $raw_opt: If the parameter is set to true then output will be raw binary data and if the parameter is set to False then output will be lowercase hexits. Return Value: This function returns a string containing the calculated message digest as lowercase hexits. Below programs uses the file gfg.txt and contents of the file are: GeeksforGeeks A Computer Science Portal for Geeks Below programs illustrate the hash_file() function in PHP: Program 1: php <?php // PHP program to illustrate // hash_file function // Create a file to calculate hash of file_put_contents('gfg.txt', 'GFG'); // Display Result echo hash_file('md5', 'gfg.txt') . "</br>"; ?> Output: 083de2341fd19dce0de9e60f3e9a8e0d Program 2: php <?php // PHP program to illustrate // hash_file function // Create a file to calculate hash of file_put_contents('gfg.txt', 'SUDO PLACEMENT'); // Display Result echo hash_file('md5', 'gfg.txt') . "</br>"; // Create a file to calculate hash of file_put_contents('gfg.txt', 'GCET'); // Display Result echo hash_file('sha1', 'gfg.txt'); ?> Output: 083de2341fd19dce0de9e60f3e9a8e0d a287a6ac47afec4140253a10b8a4c9c1e4f7a45e Reference: http://php.net/manual/en/function.hash-file.php Comment More infoAdvertise with us Next Article PHP | hash_file( ) Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | hash_final() Function The hash_final() function is an inbuilt function in PHP which is used to finalize an incremental hash and return the resulting digest. Syntax: hash_final( $context, $raw_output ) Parameters: This function accept two parameters as mention above and describe below. $context: This parameter is used to 1 min read PHP | hash_hmac_file() Function The hash_hmac_file() function is an inbuilt function in PHP that is used to generate a keyed hash value using the contents of a given file. Syntax: string hash_hmac_file( $algo, $file, $key, $raw_opt ) Parameters: This function accepts four parameters as mentioned above and described below. $algo: 2 min read PHP is_file( ) Function The is_file() function in PHP is an inbuilt function which is used to check whether the specified file is a regular file or not. The name of the file is sent as a parameter to the is_file() function and it returns True if the file is a regular file else it returns False. Syntax: bool is_file($file) 2 min read PHP | hash_algos() Function The hash_algos() function is an inbuilt function in PHP which is used to return a list of registered hashing algorithms. Syntax: array hash_algos( void ) Parameter: This function does not accepts any parameter. Return Value: This function returns a numerically indexed array which contains the list o 2 min read PHP | hash_equals() Function The hash_equals function() is an inbuilt function in PHP which is used to compares two strings using the same time whether they are equal or not.Syntax: hash_equals( $known_str, $usr_str ) Parameters: This function accept two parameters as mention above and describe below. $known_str: This parameter 1 min read PHP | hash_copy() Function The hash_copy() function is an inbuilt function in PHP which is used to get the copy of hashing context. Syntax: hash_copy( $context ) Parameters: This function accepts single parameter $context which is used to specify the hashing context returned by hash_init() function. Return Value: This functio 1 min read PHP | filesize( ) Function The filesize() function in PHP is an inbuilt function which is used to return the size of a specified file. The filesize() function accepts the filename as a parameter and returns the size of a file in bytes on success and False on failure. The result of the filesize() function is cached and a funct 2 min read PHP | filetype( ) Function The filetype() function in PHP is an inbuilt function which is used to return the file type of a specified file or a directory. The filetype() function accepts the filename as a parameter and returns one of the seven file types on success and False on failure. The seven possible return values of the 2 min read PHP fclose() Function The fclose() function in PHP closes a file that was previously opened by fopen(). Closing a file releases the resource associated with it and makes sure all the data written to the file is properly saved. Not closing files can lead to resource leaks or incomplete data writing.Syntax:bool fclose(reso 2 min read PHP | is_dir( ) Function The is_dir() function in PHP used to check whether the specified file is a directory or not. The name of the file is sent as a parameter to the is_dir() function and it returns True if the file is a directory else it returns False. Syntax: is_dir($file) Parameters Used: The is_dir() function in PHP 1 min read Like