久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <small id='M0CVL'></small><noframes id='M0CVL'>

    <i id='M0CVL'><tr id='M0CVL'><dt id='M0CVL'><q id='M0CVL'><span id='M0CVL'><b id='M0CVL'><form id='M0CVL'><ins id='M0CVL'></ins><ul id='M0CVL'></ul><sub id='M0CVL'></sub></form><legend id='M0CVL'></legend><bdo id='M0CVL'><pre id='M0CVL'><center id='M0CVL'></center></pre></bdo></b><th id='M0CVL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='M0CVL'><tfoot id='M0CVL'></tfoot><dl id='M0CVL'><fieldset id='M0CVL'></fieldset></dl></div>

    1. <legend id='M0CVL'><style id='M0CVL'><dir id='M0CVL'><q id='M0CVL'></q></dir></style></legend>
        <bdo id='M0CVL'></bdo><ul id='M0CVL'></ul>

      <tfoot id='M0CVL'></tfoot>

    2. 使用純 PHP 驗證兩個文件是否相同?

      Verifying that two files are identical using pure PHP?(使用純 PHP 驗證兩個文件是否相同?)
      <tfoot id='4fI0Y'></tfoot>
          <tbody id='4fI0Y'></tbody>
          <bdo id='4fI0Y'></bdo><ul id='4fI0Y'></ul>
          <legend id='4fI0Y'><style id='4fI0Y'><dir id='4fI0Y'><q id='4fI0Y'></q></dir></style></legend>

          <i id='4fI0Y'><tr id='4fI0Y'><dt id='4fI0Y'><q id='4fI0Y'><span id='4fI0Y'><b id='4fI0Y'><form id='4fI0Y'><ins id='4fI0Y'></ins><ul id='4fI0Y'></ul><sub id='4fI0Y'></sub></form><legend id='4fI0Y'></legend><bdo id='4fI0Y'><pre id='4fI0Y'><center id='4fI0Y'></center></pre></bdo></b><th id='4fI0Y'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4fI0Y'><tfoot id='4fI0Y'></tfoot><dl id='4fI0Y'><fieldset id='4fI0Y'></fieldset></dl></div>
            1. <small id='4fI0Y'></small><noframes id='4fI0Y'>

              1. 本文介紹了使用純 PHP 驗證兩個文件是否相同?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                TL;DR:我有一個 CMS 系統,它使用文件內容的 SHA-1 作為文件名來存儲附件(不透明文件).鑒于我已經知道兩個文件的 SHA-1 哈希匹配,如何驗證上傳的文件是否真的與存儲中的文件匹配?我想要高性能.

                TL;DR: I have an CMS system that stores attachments (opaque files) using SHA-1 of the file contents as the filename. How to verify if uploaded file really matches one in the storage, given that I already know that SHA-1 hash matches for both files? I'd like to have high performance.

                長版:

                當用戶向系統上傳新文件時,我計算上傳文件內容的 SHA-1 哈希值,然后檢查存儲后端中是否已存在具有相同哈希值的文件.PHP 在我的代碼運行之前將上傳的文件放在 /tmp 中,然后我對上傳的文件運行 sha1sum 以獲得文件內容的 SHA-1 哈希值.然后我從計算出的 SHA-1 散列計算扇出并決定 NFS 掛載目錄層次結構下的存儲目錄.(例如,如果文件內容的 SHA-1 哈希值為 37aefc1e145992f2cc16fabadcfe23eede5fb094,則永久文件名是 /nfs/data/files/37/ae/fc1e145992f2cc16eedefadcfe>.除了保存實際的文件內容,我INSERT 為用戶提交的元數據(例如Content-Type、原始文件名、日期戳等)在SQL 數據庫中添加一個新行.

                When an user uploads a new file to the system, I compute SHA-1 hash of the uploaded file contents and then check if a file with identical hash already exists in the storage backend. PHP puts the uploaded file in /tmp before my code gets to run and then I run sha1sum against the uploaded file to get SHA-1 hash of the file contents. I then compute fanout from the computed SHA-1 hash and decide storage directory under NFS mounted directory hierarchy. (For example, if the SHA-1 hash for a file contents is 37aefc1e145992f2cc16fabadcfe23eede5fb094 the permanent file name is /nfs/data/files/37/ae/fc1e145992f2cc16fabadcfe23eede5fb094.) In addition to saving the actual file contents, I INSERT a new line into a SQL database for the user submitted meta data (e.g. Content-Type, original filename, datestamp, etc).

                我目前想出的極端情況是,新上傳的文件具有 SHA-1 哈希值,該哈希值與存儲后端中的現有哈希值相匹配.我知道這種意外發生的變化是天文數字低,但我想確定.(對于故意案例,請參閱 https://shattered.io/)

                The corner case I'm currently figuring out is the case where a new uploaded file has SHA-1 hash that matches existing hash in the storage backend. I know that the changes for this happening by accident are astronomically low, but I'd like to be sure. (For on purpose case, see https://shattered.io/)

                給定兩個文件名$file_a$file_b,如何快速檢查兩個文件的內容是否相同?假設文件太大加載到內存中.對于 Python,我會使用 filecmp.cmp() 但 PHP 似乎沒有任何類似的東西.我知道這可以通過 fread() 完成并在找到不匹配的字節時中止,但我寧愿不編寫該代碼.

                Given two filenames $file_a and $file_b, how to quickly check if both files have identical contents? Assume that files are too big to be loaded into memory. With Python, I'd use filecmp.cmp() but PHP does not seem to have anything similar. I know that this can be done with fread() and aborting if a non-matching byte is found, but I'd rather not write that code.

                推薦答案

                如果你已經有一個 SHA1 和,你可以簡單地做:

                If you already have one SHA1 sum, you can simply do:

                if ($known_sha1 == sha1_file($new_file))
                

                否則

                if (filesize($file_a) == filesize($file_b)
                    && md5_file($file_a) == md5_file($file_b)
                )
                

                也檢查文件大小,以在一定程度上防止散列沖突(這已經非常不可能了).也使用 MD5,因為它比 SHA 算法快得多(但不那么獨特).

                Checking file size too, to somewhat prevent a hash collision (which is already very unlikely). Also using MD5 because it's significantly faster than the SHA algorithms (but a little less unique).

                更新:

                這是如何準確地相互比較兩個文件.

                This is how to exactly compare two files against each other.

                function compareFiles($file_a, $file_b)
                {
                    if (filesize($file_a) != filesize($file_b))
                        return false;
                
                    $chunksize = 4096;
                    $fp_a = fopen($file_a, 'rb');
                    $fp_b = fopen($file_b, 'rb');
                        
                    while (!feof($fp_a) && !feof($fp_b))
                    {
                        $d_a = fread($fp_a, $chunksize)
                        $d_b = fread($fp_b, $chunksize);
                        if ($d_a === false || $d_b === false || $d_a !== $d_b)
                        {
                            fclose($fp_a);
                            fclose($fp_b);
                            return false;
                        }
                    }
                 
                    fclose($fp_a);
                    fclose($fp_b);
                          
                    return true;
                }
                

                這篇關于使用純 PHP 驗證兩個文件是否相同?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                enable SOAP on PHP(在 PHP 上啟用 SOAP)
                Get received XML from PHP SOAP Server(從 PHP SOAP 服務器獲取接收到的 XML)
                not a valid AllXsd value(不是有效的 AllXsd 值)
                PHP SoapClient: SoapFault exception Could not connect to host(PHP SoapClient:SoapFault 異常無法連接到主機)
                Implementation of P_SHA1 algorithm in PHP(PHP中P_SHA1算法的實現)
                Sending a byte array from PHP to WCF(將字節數組從 PHP 發送到 WCF)
                  <tbody id='R99F8'></tbody>

                    <bdo id='R99F8'></bdo><ul id='R99F8'></ul>
                    <tfoot id='R99F8'></tfoot>
                        <i id='R99F8'><tr id='R99F8'><dt id='R99F8'><q id='R99F8'><span id='R99F8'><b id='R99F8'><form id='R99F8'><ins id='R99F8'></ins><ul id='R99F8'></ul><sub id='R99F8'></sub></form><legend id='R99F8'></legend><bdo id='R99F8'><pre id='R99F8'><center id='R99F8'></center></pre></bdo></b><th id='R99F8'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='R99F8'><tfoot id='R99F8'></tfoot><dl id='R99F8'><fieldset id='R99F8'></fieldset></dl></div>

                        <small id='R99F8'></small><noframes id='R99F8'>

                          <legend id='R99F8'><style id='R99F8'><dir id='R99F8'><q id='R99F8'></q></dir></style></legend>

                        1. 主站蜘蛛池模板: 日韩精品成人免费观看视频 | 国产伊人久久久 | 精品久久久久久亚洲精品 | 国产激情视频网 | 中文字幕av在线 | 欧美日韩国产一区二区三区 | 国产高清精品一区二区三区 | 免费观看a级毛片在线播放 黄网站免费入口 | 最新av在线网址 | 欧美一区二区免费在线 | 黄色一级免费 | 天天操 天天操 | 久久精品视频亚洲 | 精品久久久久国产免费第一页 | 一区二区三区高清 | 欧美色综合一区二区三区 | 国产三区在线观看视频 | 一区二区视频 | 午夜影院在线视频 | 九九热热九九 | 97精品超碰一区二区三区 | 国产免费拔擦拔擦8x高清 | 久草新在线 | 美女中文字幕视频 | 国产福利在线 | 亚洲国产成人av好男人在线观看 | 成人h免费观看视频 | 国产成人在线视频播放 | 久久精品久久久久久 | www日本在线观看 | 91久久久久久久久久久 | 亚洲狠狠丁香婷婷综合久久久 | 69热视频在线观看 | 日本一卡精品视频免费 | 日韩精品一区二区三区中文在线 | 伊人在线 | aaa大片免费观看 | 成人h视频在线观看 | 国产精品不卡一区二区三区 | 国产精品自拍一区 | 国产目拍亚洲精品99久久精品 |