mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
Save attachments as ...
This commit is contained in:
parent
f5f067f1f3
commit
48b91fb957
20 changed files with 687 additions and 76 deletions
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue