您好,欢迎访问一九零五行业门户网

php对文件进行hash运算的方法_PHP

本文实例讲述了php对文件进行hash运算的方法。分享给大家供大家参考。具体如下:
这段代码非常有用,如果你下载了一个文件,网站提供了hash结果,你可以对你下载下来的文件进行hash运算,以验证下载的文件是否正确。
hash (check) files 0){ switch($_files[file][error]){ case 1: echo error: the uploaded file exceeds the upload_max_filesize directive in php.ini
; break; case 2: echo error: the uploaded file exceeds the max_file_size directive that was specified in the html form.
; break; case 3: echo error: the uploaded file was only partially uploaded.
; break; case 4: echo error: no file was uploaded.
; break; case 6: echo error: missing a temporary folder.
; break; case 7: echo error: failed to write file to disk.
; break; case 8: echo error: a php extension stopped the file upload.
; break; default: echo unknown error occured.
; } } else { echo 'upload: ' . $_files['file']['name'] . '
'; echo 'type: ' . $_files['file']['type'] . '
'; echo 'size: ' . (round($_files['file']['size'] / 1024, 2)) . ' kb
'; if(array_search($_post['algo'], hash_algos())===false){ echo 'unknown hashing algorithm requested.
'; } else { echo 'hashing algorithm: '. $_post['algo'] . '
'; $hash = hash_file($_post['algo'], $_files['file']['tmp_name']); echo 'calculated hash: ' . $hash . '
'; if($_post['exphash']!=='none' && !empty($_post['exphash'])){ echo 'expected hash: ' . $_post['exphash'] . '
'; echo ($hash==$_post['exphash'])? 'hash matched expected value.' : 'hash did not match expected value.'; echo '
'; } } } ?>
again filename:
expected hash(optional):
choose an algorithm (this is the list of all the available algorithms in your php installation)

希望本文所述对大家的php程序设计有所帮助。
其它类似信息

推荐信息