PHP | hash_file( ) Function
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 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 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
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- D3.js | d3.set.has() Function
- D3.js | d3.map.set() Function
- PHP | max( ) Function
- p5.js | nf() Function
- p5.js | nfc() function
- PHP | Ds\Set contains() Function
- CSS | rgb() Function
- PHP | Ds\Set last() Function
- PHP | Ds\Set first() Function
- D3.js | d3.min() function
- p5.js | box() Function
- PHP | next() Function
- PHP | pos() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



