1

So for those who do not know PHP both 64bit and 32bit builds for windows have a design limitation what means functions like "filesize", "md5_file", "sha1_file" etc. Can not read files over the size of 2GB and the php script shall error or return a invalid/incorrect size for the file.

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

A soloution with the windows command prompt is as follows.

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

How can i use that in my PHP code in order to recieve the sha1 sum of the large file.

C0nw0nk
  • 870
  • 2
  • 13
  • 29

2 Answers2

1
<?php

$result = shell_exec ('CertUtil -hashfile "C:\Users\C0n\Desktop\2GB-file.MP4" SHA1');

var_dump ($result);
Halayem Anis
  • 7,654
  • 2
  • 25
  • 45
0

My working code is as follows.

//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;
}
C0nw0nk
  • 870
  • 2
  • 13
  • 29