【问题标题】:Getting an Adobe Air MD5 of a file to match PHP MD5获取文件的 Adob​​e Air MD5 以匹配 PHP MD5
【发布时间】:2011-10-17 22:10:17
【问题描述】:

我需要两个函数,一个在 PHP 中,另一个在 Adob​​e AIR javascript 中,它们可以计算文件的 MD5 哈希并为同一文件返回相同的结果。

我正在使用 PHPJS 的 MD5 函数来处理 javascript:

function GetFileMD5(path) {
  var file = new air.File(path);
  if(file.exists) {
    var fileStream = new air.FileStream();              
    fileStream.open(file, air.FileMode.READ);
    var content = fileStream.readUTFBytes(fileStream.bytesAvailable);
    fileStream.close();
    return md5(content);
  } 
}

在 PHP 中:

function GetFileMD5($path) {
  if($file = fopen($path,'rb')) {
    $content = fread($file, $file.size);
    fclose($file);
    return md5($content);
  }
}

我不确定要使用哪个文件流函数(而不是 readUTFBytes 来匹配 fread)。我尝试了各种组合。

有什么帮助吗?

【问题讨论】:

    标签: php javascript air md5 filestream


    【解决方案1】:

    PHP 版本肯定是错误的。 $file.size 正在生成一个无意义的结果,可能类似于 "Resource id #7size"。

    一个正确(而且更简单)的实现可能是:

    function GetFileMD5($path) {
        return md5(file_get_contents($path));
    }
    

    【讨论】:

      【解决方案2】:

      你也可以使用md5_file函数。

      【讨论】:

        猜你喜欢
        • 2016-06-24
        • 1970-01-01
        • 1970-01-01
        • 2010-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-19
        • 1970-01-01
        相关资源
        最近更新 更多