Is there a way to make a PHP script calculate a local file's SHA1 sum before the...

Daniel K

New member
...download and compare it? I was thinking some client side script could calculate the file's SHA1sum, store it in a variable which is passed to the PHP script with post and then after the download is complete, return the SHA1sum of the downloaded file by having php execute a shell command.

Is this easy? If so, what should i use on the client side, and what should I use on the server? I want it to be automatic / user-transparent.
 
Most systems have md5 installed, so it would be easier to use that. Then, use the hashing functions built into PHP:

http://www.php.net/manual/en/ref.hash.php

There are a couple of functions there that will do exactly what you want.

The problem is doing it on the client side. You have to assume that the client system has some kind of encryption library installed, but even if it did, I can't think of a way you could run it remotely.

You could easily figure out an md5 hash for the file on the receiving end, and display it to the sender, but until you have the actual file, there's no way of knowing what the hash value will be.
 
Back
Top