本文整理匯總了PHP中MailSo\Base\Utils::SmartFileExists方法的典型用法代碼示例。如果您正苦於以下問題:PHP Utils::SmartFileExists方法的具體用法?PHP Utils::SmartFileExists怎麽用?PHP Utils::SmartFileExists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MailSo\Base\Utils
的用法示例。
在下文中一共展示了Utils::SmartFileExists方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: DoAttachmentsActions
/**
* @return array
*
* @throws \MailSo\Base\Exceptions\Exception
*/
public function DoAttachmentsActions()
{
if (!$this->GetCapa(false, \RainLoop\Enumerations\Capa::ATTACHMENTS_ACTIONS)) {
return $this->FalseResponse(__FUNCTION__);
}
$oAccount = $this->initMailClientConnection();
$sAction = $this->GetActionParam('Do', '');
$aHashes = $this->GetActionParam('Hashes', null);
$mResult = false;
$bError = false;
$aData = false;
if (\is_array($aHashes) && 0 < \count($aHashes)) {
$aData = array();
foreach ($aHashes as $sZipHash) {
$aResult = $this->getMimeFileByHash($oAccount, $sZipHash);
if (\is_array($aResult) && !empty($aResult['FileHash'])) {
$aData[] = $aResult;
} else {
$bError = true;
break;
}
}
}
$oFilesProvider = $this->FilesProvider();
if (!empty($sAction) && !$bError && \is_array($aData) && 0 < \count($aData) && $oFilesProvider && $oFilesProvider->IsActive()) {
$bError = false;
switch (\strtolower($sAction)) {
case 'zip':
if (\class_exists('ZipArchive')) {
$sZipHash = \MailSo\Base\Utils::Md5Rand();
$sZipFileName = $oFilesProvider->GenerateLocalFullFileName($oAccount, $sZipHash);
if (!empty($sZipFileName)) {
$oZip = new \ZipArchive();
$oZip->open($sZipFileName, \ZIPARCHIVE::CREATE | \ZIPARCHIVE::OVERWRITE);
$oZip->setArchiveComment('RainLoop/' . APP_VERSION);
foreach ($aData as $aItem) {
$sFileName = (string) (isset($aItem['FileName']) ? $aItem['FileName'] : 'file.dat');
$sFileHash = (string) (isset($aItem['FileHash']) ? $aItem['FileHash'] : '');
if (!empty($sFileHash)) {
$sFullFileNameHash = $oFilesProvider->GetFileName($oAccount, $sFileHash);
if (!$oZip->addFile($sFullFileNameHash, $sFileName)) {
$bError = true;
}
}
}
if (!$bError) {
$bError = !$oZip->close();
} else {
$oZip->close();
}
}
foreach ($aData as $aItem) {
$sFileHash = (string) (isset($aItem['FileHash']) ? $aItem['FileHash'] : '');
if (!empty($sFileHash)) {
$oFilesProvider->Clear($oAccount, $sFileHash);
}
}
if (!$bError) {
$mResult = array('Files' => array(array('FileName' => 'attachments.zip', 'Hash' => \RainLoop\Utils::EncodeKeyValuesQ(array('V' => APP_VERSION, 'Account' => $oAccount ? \md5($oAccount->Hash()) : '', 'FileName' => 'attachments.zip', 'MimeType' => 'application/zip', 'FileHash' => $sZipHash)))));
}
}
break;
case 'owncloud':
$mResult = false;
if (\RainLoop\Utils::IsOwnCloudLoggedIn() && \class_exists('OCP\\Files')) {
$sSaveFolder = $this->Config()->Get('labs', 'owncloud_save_folder', '');
if (empty($sSaveFolder)) {
$sSaveFolder = 'Attachments';
}
$oFiles = \OCP\Files::getStorage('files');
if ($oFilesProvider && $oFiles && $oFilesProvider->IsActive() && \method_exists($oFiles, 'file_put_contents')) {
if (!$oFiles->is_dir($sSaveFolder)) {
$oFiles->mkdir($sSaveFolder);
}
$mResult = true;
foreach ($aData as $aItem) {
$sSavedFileName = isset($aItem['FileName']) ? $aItem['FileName'] : 'file.dat';
$sSavedFileHash = !empty($aItem['FileHash']) ? $aItem['FileHash'] : '';
if (!empty($sSavedFileHash)) {
$fFile = $oFilesProvider->GetFile($oAccount, $sSavedFileHash, 'rb');
if (\is_resource($fFile)) {
$sSavedFileNameFull = \MailSo\Base\Utils::SmartFileExists($sSaveFolder . '/' . $sSavedFileName, function ($sPath) use($oFiles) {
return $oFiles->file_exists($sPath);
});
if (!$oFiles->file_put_contents($sSavedFileNameFull, $fFile)) {
$mResult = false;
}
if (\is_resource($fFile)) {
@\fclose($fFile);
}
}
}
}
}
}
//.........這裏部分代碼省略.........