Specifically as follows:
This code is very useful, if you download a file, the site provides a hash results, you can download the file to hash, to verify that the downloaded file is correct.
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 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 |
<html> <head> <title>hash (Check) files</title> <style type= ' text/css ' > #ok {color:green ;} #nono {color:red} </style> </head> <body> <?php if (!empty ($_files)) {if ($_files["file"] ["Error" ] > 0) {switch ($_files["file"] ["error"]) {case 1:echo ' <b id= ' nono ' >error:the uploaded file exceeds the Upload_ max_filesize directive in php.ini</b><br> "; Break Case 2:echo "<b id= ' Nono ' >error:the uploaded file exceeds the max_file_size directive this is specified in the HT ML form.</b><br> "; Break Case 3:echo "<b id= ' Nono ' >error:the uploaded file is only partially uploaded.</b><br>"; Break Case 4:echo "<b id= ' Nono ' >error:no file is uploaded.</b><br>"; Break Case 6:echo "<b id= ' Nono ' >error:missing a temporary folder.</b><br>"; Break Case 7:echo "<b id= ' Nono ' >error:failed to write file to Disk.</b><br>"; Break Case 8:echo "<b id= ' Nono ' >error:a PHP extension stopped the file upload.</b><br>; Break Default:echo "<b id= ' Nono ' >unknown error occured.</b><br>"; } else {echo ' Upload: '. $_files[' file ' [' Name ']. ' <br> '; Echo ' Type: '. $_files[' file ' [' type ']. ' <br> '; Echo ' Size: '. (Round ($_files[' file '] [' size ']/1024, 2)). ' Kb<br><br> '; if (Array_search ($_post[' Algo '], Hash_algos ()) ===false) {echo ' Unknown hashing algorithm ';} else { echo ' Hashing algorithm: '. $_post[' Algo ']. ' <br> '; $hash = Hash_file ($_post[' Algo '), $_files[' file ' [' Tmp_name ']]; Echo ' Calculated hash: '. $hash. ' <br> '; if ($_post[' Exphash ']!== ' None ' &&!empty ($_post[' Exphash ')) {echo ' expected hash: '. $_post[' Exphash ']. ' <br><br> '; Echo ($hash ==$_post[' Exphash '])? ' <b id= ' OK ' >hash matched expected value.</b> ': ' <b id= ' Nono ' >hash did not match expected VALUE.</B&G t; '; Echo ' <br> '; } } }?> <br> <button onclick= "Document.location.reload (True)" >Again</button> <?php} else {?> & Lt;form action= "" method= "Post" enctype= "Multipart/form-data" > <input type= "hidden" name= "Exphash" value= "None" > <label for= "file" >Filename:</label> <input type= "file" name= "file" id= "file" > <input type= " Submit "Name=" submit "value=" submit "/><br> <label>expected hash (optional): <input type=" Text "name= "Exphash" size= "M" ></label> <br><br>choose a algorithm (this are the list of all available Algo Rithms in your PHP installation) <br> <?php foreach (Hash_algos () as $algo) {if ($algo = = ' MD5 ') {echo <label> <input type= ' Radio ' name= ' algo ' value= ' $algo ' checked= ' checked ' > $algo </label><br> '; else {echo ' <label><input type= ' radio ' name= ' algo ' value= ' $algo ' > $algo </label><br> ';}} ?> </form> <?php}?> </body> </html> |