【问题标题】:Windows PHP Replacing SHA1_FILE >= 2GB error fixWindows PHP 替换 SHA1_FILE >= 2GB 错误修复
【发布时间】:2015-05-17 03:42:28
【问题描述】:

因此,对于那些不了解 PHP 的 64 位和 32 位 Windows 版本的人来说,这意味着“filesize”、“md5_file”、“sha1_file”等函数的设计限制。无法读取大小超过 2GB 的文件,并且php 脚本应出错或返回文件的无效/不正确大小。

$fname = $_FILES['Filedata']['tmp_name'];
$filesource = sha1_file($fname);

windows命令提示符的解决方法如下。

CertUtil -hashfile "C:\Users\C0n\Desktop\2GB-file.MP4" SHA1

如何在我的 PHP 代码中使用它来接收大文件的 sha1 总和。

【问题讨论】:

    标签: php windows sha1


    【解决方案1】:
    <?php
    
    $result = shell_exec ('CertUtil -hashfile "C:\Users\C0n\Desktop\2GB-file.MP4" SHA1');
    
    var_dump ($result);
    

    【讨论】:

      【解决方案2】:

      我的工作代码如下。

      //Check OS is Windows
      if(substr(PHP_OS, 0, 3) == "WIN") {
      //input file    
      $input = 'CertUtil -hashfile "C:\Users\C0n\Desktop\2GB-file.MP4" SHA1';
      //Eexecute input and put the response into a array
      exec($input, $response);
      //Remove spaces between the hash output.
      $str = str_replace(' ', '', $response[1]);
      //Display the hash of the file
      echo $str;
      }
      

      【讨论】:

        猜你喜欢
        • 2012-06-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多