xref: /PHP-7.4/ext/hash/tests/hash_file_basic.phpt (revision d7a3edd4)
1--TEST--
2Hash: hash_file() function : basic functionality
3--CREDITS--
4Felix De Vliegher <felix.devliegher@gmail.com>
5--FILE--
6<?php
7/* Prototype  : string hash_file(string algo, string filename[, bool raw_output = false])
8 * Description: Generate a hash of a given file
9 * Source code: ext/hash/hash.c
10 * Alias to functions:
11 */
12
13echo "*** Testing hash_file() : basic functionality ***\n";
14
15// Set up file
16$filename = 'hash_file_basic_example.txt';
17file_put_contents( $filename, 'The quick brown fox jumped over the lazy dog.' );
18
19var_dump( hash_file( 'md5', $filename ) );
20var_dump( hash_file( 'sha1', $filename ) );
21var_dump( hash_file( 'sha256', $filename ) );
22var_dump( hash_file( 'sha512', $filename ) );
23
24var_dump( base64_encode( hash_file( 'md5', $filename, true ) ) );
25
26?>
27===DONE===
28--CLEAN--
29<?php
30
31$filename = 'hash_file_basic_example.txt';
32unlink( $filename );
33
34?>
35--EXPECT--
36*** Testing hash_file() : basic functionality ***
37string(32) "5c6ffbdd40d9556b73a21e63c3e0e904"
38string(40) "c0854fb9fb03c41cce3802cb0d220529e6eef94e"
39string(64) "68b1282b91de2c054c36629cb8dd447f12f096d3e3c587978dc2248444633483"
40string(128) "0a8c150176c2ba391d7f1670ef4955cd99d3c3ec8cf06198cec30d436f2ac0c9b64229b5a54bdbd5563160503ce992a74be528761da9d0c48b7c74627302eb25"
41string(24) "XG/73UDZVWtzoh5jw+DpBA=="
42===DONE===
43