日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

php對(duì)文件進(jìn)行hash運(yùn)算的方法_PHP教程

編輯Tag賺U幣
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!

推薦:php計(jì)算給定時(shí)間之前的函數(shù)用法實(shí)例
這里給定一個(gè)時(shí)間,計(jì)算這個(gè)時(shí)間在多久前,比如:2天前,1年前

這篇文章主要介紹了php對(duì)文件進(jìn)行hash運(yùn)算的方法,涉及針對(duì)文件的hash運(yùn)算技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php對(duì)文件進(jìn)行hash運(yùn)算的方法。分享給大家供大家參考。具體如下:

這段代碼非常有用,如果你下載了一個(gè)文件,網(wǎng)站提供了hash結(jié)果,你可以對(duì)你下載下來(lái)的文件進(jìn)行hash運(yùn)算,以驗(yàn)證下載的文件是否正確。

  1. <html> 
  2. <head> 
  3.   <title>Hash (Check) Files</title> 
  4.   <style type='text/css'
  5.    #ok{color:green;} 
  6.    #nono{color:red;} 
  7.   </style> 
  8. </head> 
  9. <body> 
  10.  <?php 
  11.    if(!emptyempty($_FILES)){ 
  12.    if ($_FILES["file"]["error"] > 0){ 
  13.     switch($_FILES["file"]["error"]){ 
  14.      case 1: 
  15.      echo "<b id='nono'>Error: The uploaded file exceeds the upload_max_filesize directive in php.ini</b><br>"
  16.      break
  17.      case 2: 
  18.      echo "<b id='nono'>Error: The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.</b><br>"
  19.      break
  20.      case 3: 
  21.      echo "<b id='nono'>Error: The uploaded file was only partially uploaded.</b><br>"
  22.      break
  23.      case 4: 
  24.      echo "<b id='nono'>Error: No file was uploaded.</b><br>"
  25.      break
  26.      case 6: 
  27.      echo "<b id='nono'>Error: Missing a temporary folder.</b><br>"
  28.      break
  29.      case 7: 
  30.      echo "<b id='nono'>Error: Failed to write file to disk.</b><br>"
  31.      break
  32.      case 8: 
  33.      echo "<b id='nono'>Error: A PHP extension stopped the file upload.</b><br>"
  34.      break
  35.      default
  36.      echo "<b id='nono'>Unknown error occured.</b><br>"
  37.     } 
  38.    } else { 
  39.     echo 'Upload: ' . $_FILES['file']['name'] . '<br>'
  40.     echo 'Type: ' . $_FILES['file']['type'] . '<br>'
  41.     echo 'Size: ' . (round($_FILES['file']['size'] / 1024, 2)) . ' Kb<br><br>'
  42.     if(array_search($_POST['algo'], hash_algos())===false){ 
  43.     echo 'Unknown hashing algorithm requested.<br>'
  44.     } else { 
  45.     echo 'Hashing Algorithm: '$_POST['algo'] . '<br>'
  46.     $hash = hash_file($_POST['algo'], $_FILES['file']['tmp_name']); 
  47.     echo 'Calculated hash: ' . $hash . '<br>'
  48.     if($_POST['exphash']!=='none' && !emptyempty($_POST['exphash'])){ 
  49.       echo 'Expected hash:   ' . $_POST['exphash'] . '<br><br>'
  50.       echo ($hash==$_POST['exphash'])? '<b id="ok">Hash matched expected value.</b>' : '<b id="nono">Hash did not match expected value.</b>'
  51.       echo '<br>'
  52.     } 
  53.     } 
  54.    } 
  55.    ?> 
  56.    <br> 
  57.    <button onClick="document.location.reload(true)">Again</button> 
  58.     <?php 
  59.    } else { 
  60.   ?> 
  61.   <form action="" method="post" enctype="multipart/form-data"
  62.    <input type="hidden" name="exphash" value="none"
  63.    <label for="file">Filename:</label> 
  64.    <input type="file" name="file" id="file"
  65.    <input type="submit" name="submit" value="Submit" /><br> 
  66.    <label>Expected hash(optional): <input type="text" name="exphash" size="100"></label> 
  67.    <br><br>Choose an algorithm (This is the list of all the available algorithms in your php installation)<br> 
  68.    <?php 
  69.    foreach(hash_algos() as $algo){ 
  70.     if($algo=='md5'){ 
  71.     echo "<label><input type='radio' name='algo' value='$algo' checked='checked'>$algo</label><br>"
  72.     } else { 
  73.     echo "<label><input type='radio' name='algo' value='$algo'>$algo</label><br>"
  74.     } 
  75.    } 
  76.    ?> 
  77.   </form> 
  78.  <?php 
  79.    } 
  80.   ?> 
  81. </body> 
  82. </html> 

分享:php實(shí)現(xiàn)的mongodb操作類實(shí)例
本文實(shí)例講述了php實(shí)現(xiàn)的mongodb操作類。分享給大家供大家參考。具體如下:

來(lái)源:模板無(wú)憂//所屬分類:PHP教程/更新時(shí)間:2015-04-03
相關(guān)PHP教程