Example 1 — Hash a File
Create a small temporary file, then hash it.
<?php
$file = tempnam(sys_get_temp_dir(), "demo");
file_put_contents($file, "hello");
echo md5_file($file), PHP_EOL;
unlink($file); How It Works
- Make a temp file. tempnam gives a safe unique path.
- Write some text. The file now contains hello.
- Call md5_file. It hashes the file contents.
- Clean up. unlink deletes the temporary file.

