Save attachments as ...

This commit is contained in:
RainLoop Team 2015-04-25 02:15:11 +04:00
parent f5f067f1f3
commit 48b91fb957
20 changed files with 687 additions and 76 deletions

View file

@ -235,6 +235,56 @@ END;
return $sCharset;
}
/**
* @param string $sFilePath
* @param function $fFileExistsCallback = null
*
* @return string
*/
public static function SmartFileExists($sFilePath, $fFileExistsCallback = null)
{
$sFilePath = \str_replace('\\', '/', \trim($sFilePath));
if (!$fFileExistsCallback)
{
$fFileExistsCallback = function ($sPath) {
return \file_exists($sPath);
};
}
if (!\call_user_func($fFileExistsCallback, $sFilePath))
{
return $sFilePath;
}
$aFileInfo = \pathinfo($sFilePath);
$iIndex = 0;
do
{
$iIndex++;
$sFilePathNew = $aFileInfo['dirname'].'/'.
\preg_replace('/\(\d{1,2}\)$/', '', $aFileInfo['filename']).
' ('.$iIndex.')'.
(empty($aFileInfo['extension']) ? '' : '.'.$aFileInfo['extension'])
;
if (!\call_user_func($fFileExistsCallback, $sFilePathNew))
{
$sFilePath = $sFilePathNew;
break;
}
else if (10 < $iIndex)
{
break;
}
}
while (true);
return $sFilePath;
}
/**
* @return bool
*/