Reputation: 43
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:
$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.
Upvotes: 1
Views: 266
Reputation: 43
the code works but i had to revise it Unix text file end each line with a line feed character. DOS/Windows text files end each line with a carriage return and line feed.
so the answer was
$d = str_replace("\r\n","\n",file_get_contents_utf8($filefullpath));
$s = strlen( $d );
$x = sha1("blob " .$s. "\0" .$d);
Upvotes: 2