A Clockwork Orange
A Clockwork Orange

Reputation: 24793

PHP - Hash contents of uploaded file

I would like to hash the contents of an uploaded file in MD5. The file will not be saved locally so it only exists in a tmp directory.

How can I do this? Thanks.

Upvotes: 10

Views: 13362

Answers (3)

Charles Brunet
Charles Brunet

Reputation: 23120

You can use md5_file() or sha1_file() function. For example, if your post variable is filevar:

$myhash = md5_file($_FILES['filevar']['tmp_name']);

Upvotes: 21

Thoman
Thoman

Reputation: 792

MD5() for string and md5_file() for files

Upvotes: 2

Pascal MARTIN
Pascal MARTIN

Reputation: 400952

You can use md5_file(), even on your temporary file.

Upvotes: 3

Related Questions