这段代码非常有用,如果你下载了一个文件,网站提供了hash结果,你可以对你下载下来的文件进行hash运算,以验证下载的文件是否正确。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
hash (check) files
#ok{color:green;}
#nono{color:red;}
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)
http://www.bkjia.com/phpjc/978261.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/978261.htmltecharticlephp对文件进行hash运算的方法 具体如下: 这段代码非常有用,如果你下载了一个文件,网站提供了hash结果,你可以对你下载下来的文件进行...
