简体   繁体   English

生成文件sha1哈希以匹配php中的githubs

[英]generate a files sha1 hash to match githubs in php

I am trying to generate file sha hash's on my local webpage to see if the file version if different from my git repo the code i have now is this: 我正在尝试在本地网页上生成文件sha哈希,以查看文件版本(如果不同于我的git repo),现在的代码是这样的:

$d = file_get_contents($filefullpath);
$s = strlen($d);
$x = sha1("blob " .$s. "\0" .$d.'');

But the sha of my file never matches git;s sha, and i need to do in in pure php code no modules. 但是我文件的sha永远不匹配git; s sha,我需要在纯PHP代码中执行任何模块。

the code works but i had to revise it Unix text file end each line with a line feed character. 该代码有效,但我必须对其进行修改,Unix文本文件在每行末尾都带有换行符。 DOS/Windows text files end each line with a carriage return and line feed. DOS / Windows文本文件在每行末尾都有回车符和换行符。

so the answer was 所以答案是

$d = str_replace("\r\n","\n",file_get_contents_utf8($filefullpath));
$s = strlen( $d );
$x = sha1("blob " .$s. "\0" .$d);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM