本文整理汇总了PHP中Folder::getModel方法的典型用法代码示例。如果您正苦于以下问题:PHP Folder::getModel方法的具体用法?PHP Folder::getModel怎么用?PHP Folder::getModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Folder
的用法示例。
在下文中一共展示了Folder::getModel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDefaultAttachmentSRC
public static function getDefaultAttachmentSRC($blnReturnPath = false)
{
$objFolder = new \Folder('files/submissions/uploads');
if ($blnReturnPath) {
return $objFolder->path;
}
if (\Validator::isUuid($objFolder->getModel()->uuid)) {
return class_exists('Contao\\StringUtil') ? \StringUtil::binToUuid($objFolder->getModel()->uuid) : \String::binToUuid($objFolder->getModel()->uuid);
}
return null;
}
示例2: getUniqueFileNameWithinTarget
/**
* Get a unique filename within given target folder, remove uniqid() suffix from file (optional, add $strPrefix) and append file count by name to
* file if file with same name already exists in target folder
*
* @param string $strTarget The target file path
* @param string $strPrefix A uniqid prefix from the given target file, that was added to the file before and should be removed again
* @param $i integer Internal counter for recursion usage or if you want to add the number to the file
*
* @return string | false The filename with the target folder and unique id or false if something went wrong (e.g. target does not exist)
*/
public static function getUniqueFileNameWithinTarget($strTarget, $strPrefix = null, $i = 0)
{
$objFile = new \File($strTarget, true);
$strTarget = ltrim(str_replace(TL_ROOT, '', $strTarget), '/');
$strPath = str_replace('.' . $objFile->extension, '', $strTarget);
if ($strPrefix && ($pos = strpos($strPath, $strPrefix)) !== false) {
$strPath = str_replace(substr($strPath, $pos, strlen($strPath)), '', $strPath);
$strTarget = $strPath . '.' . $objFile->extension;
}
// Create the parent folder
if (!file_exists($objFile->dirname)) {
$objFolder = new \Folder(ltrim(str_replace(TL_ROOT, '', $objFile->dirname), '/'));
// something went wrong with folder creation
if ($objFolder->getModel() === null) {
return false;
}
}
if (file_exists(TL_ROOT . '/' . $strTarget)) {
// remove suffix
if ($i > 0 && StringUtil::endsWith($strPath, '_' . $i)) {
$strPath = rtrim($strPath, '_' . $i);
}
// increment counter & add extension again
$i++;
// for performance reasons, add new unique id to path to make recursion come to end after 100 iterations
if ($i > 100) {
return static::getUniqueFileNameWithinTarget(static::addUniqIdToFilename($strPath . '.' . $objFile->extension, null, false));
}
return static::getUniqueFileNameWithinTarget($strPath . '_' . $i . '.' . $objFile->extension, $strPrefix, $i);
}
return $strTarget;
}
示例3: addHomeDir
/**
* Adds a new home dir to a member. Therefore a folder named with the members's id is created in $varRootFolder
*
* @param $varMember object|int The member as object or member id
* @param $strBooleanPropertyName string The name of the boolean member property (e.g. "assignDir")
* @param $strPropertyName string The name of the member property (e.g. "homeDir")
* @param $varRootFolder string|object The base folder as instance of \FilesModel, path string or uuid
* @param bool|false $blnOverwrite bool Determines if an existing folder can be overridden
*
* @return bool|string Returns true, if a directory has already been linked with the member, the folders uuid if successfully added and false if errors occured.
*/
public static function addHomeDir($varMember, $strBooleanPropertyName = 'assignDir', $strPropertyName = 'homeDir', $varRootFolder = 'files/members', $blnOverwrite = false)
{
if (($objMember = is_numeric($varMember) ? \MemberModel::findByPk($varMember) : $varMember) === null) {
return false;
}
// already set
if ($objMember->{$strBooleanPropertyName} && $objMember->{$strPropertyName} && !$blnOverwrite) {
return true;
}
if (!$varRootFolder instanceof \FilesModel) {
if (\Validator::isUuid($varRootFolder)) {
$objFolderModel = \FilesModel::findByUuid($varRootFolder);
$strPath = $objFolderModel->path;
} else {
$strPath = $varRootFolder;
}
} else {
$strPath = $varRootFolder->path;
}
$strPath = str_replace(TL_ROOT, '', $strPath);
if (!$strPath) {
return false;
}
$objMember->{$strBooleanPropertyName} = true;
$strPath = ltrim($strPath, '/') . '/' . $objMember->id;
$objHomeDir = new \Folder($strPath);
$objMember->{$strPropertyName} = $objHomeDir->getModel()->uuid;
$objMember->save();
return $objHomeDir->getModel()->uuid;
}