Works on files encryption

This commit is contained in:
Regis Houssin
2009-12-15 20:45:21 +00:00
parent 74982edb02
commit 1a24cfc603

View File

@@ -301,5 +301,69 @@ function dol_is_file($pathoffile)
$newpathoffile=dol_osencode($pathoffile);
return is_file($newpathoffile);
}
/**
* Reading or writing to a text file
*
* @param $file File to open or create
* @param $mode Mode to open file : r = returns the text of a file, or returns FALSE if the file isn't found
* w = creates or overrides a file with the text
* r+ = reads a text file, then writes the text to the end of the file
* @param $input String of text
* @return boolean True if ok, false if error
*/
function dol_openfile($file, $mode, $input)
{
if ($mode == "r")
{
if (file_exists($file))
{
$handle = fopen($file, "r");
$output = fread($handle, filesize($file));
return $output; // output file text
}
else
{
return false; // failed.
}
}
elseif ($mode == "w")
{
$handle = fopen($file, "w");
if (!fwrite($handle, $input))
{
return false; // failed.
}
else
{
return true; //success.
}
}
elseif ($mode == "r+")
{
if (file_exists($file) && isset($input))
{
$handle = fopen($file, "r+");
$read = fread($handle, filesize($file));
$data = $read.$input;
if (!fwrite($handle, $data))
{
return false; // failed.
}
else
{
return true; // success.
}
}
else
{
return false; // failed.
}
}
else
{
return false; // failed.
}
fclose($handle);
}
?>