Ulminia
Ulminia

Reputation: 43

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:

$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

Answers (1)

Ulminia
Ulminia

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

Related Questions