file : add md5_file and sha1_file support

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3029 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2016-09-08 09:05:17 +00:00
parent 04978bc31b
commit 413324cf42

View File

@@ -296,6 +296,28 @@ class file
return $res;
}
/** Calculate the md5 sum of a file
* @param $filename The file to hash
* @return the calulated hash
* @throws If the file doesn't exists
*/
public function md5_file ($filename)
{
$this->debug (2, "md5_file ($filename)");
$filename = $this->realpath ($filename);
$this->checkPathRO (dirname ($filename));
if (! is_file ($filename))
throw new \Exception (sprintf (dgettext ("domframework",
"File '%s' is not a file"),
$filename), 500);
if (! is_readable ($filename))
throw new \Exception (sprintf (dgettext ("domframework",
"File '%s' is not readable"),
$filename), 500);
return md5_file ($filename);
}
/** Create a new directory
* @param $pathname The directory to create
* @param $mode The mode to create (0777 by default)
@@ -517,6 +539,27 @@ class file
return $res;
}
/** Calculate the sha1 sum of a file
* @param $filename The file to hash
* @return the calulated hash
* @throws If the file doesn't exists
*/
public function sha1_file ($filename)
{
$this->debug (2, "sha1_file ($filename)");
$filename = $this->realpath ($filename);
$this->checkPathRO (dirname ($filename));
if (! is_file ($filename))
throw new \Exception (sprintf (dgettext ("domframework",
"File '%s' is not a file"),
$filename), 500);
if (! is_readable ($filename))
throw new \Exception (sprintf (dgettext ("domframework",
"File '%s' is not readable"),
$filename), 500);
return sha1_file ($filename);
}
/** Create a new file or update the timestamp if the file exists
* @param string $filename the filename
* @param int $time the timestamp to use (actual timestamp if not defined)