本文整理汇总了PHP中CUtils::checkNameInvalid方法的典型用法代码示例。如果您正苦于以下问题:PHP CUtils::checkNameInvalid方法的具体用法?PHP CUtils::checkNameInvalid怎么用?PHP CUtils::checkNameInvalid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUtils
的用法示例。
在下文中一共展示了CUtils::checkNameInvalid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateFileName
/**
* 更名
*/
public function updateFileName($id, $name, &$message)
{
if (CUtils::checkNameInvalid($name) || strstr($name, '&') || strstr($name, ';')) {
$message = Yii::t("front_common", "name_error");
return false;
}
$model = $this->findByAttributes(array('id' => $id));
if (empty($model)) {
$message = Yii::t("admin_common", "rename_file_not_found");
return false;
}
$oldPath = $model['file_path'];
$model['file_name'] = $name;
$model['file_path'] = dirname($model['file_path']) . "/" . $name;
//
// 判断同名否
//
$same = $this->findByAttributes(array('file_path' => $model['file_path']));
if ($same) {
$message = Yii::t("admin_common", "rename_file_already_exists");
return false;
}
$time = (int) time();
$model['file_update_time'] = $time;
$path = $model['file_path'];
$context = $path;
$device_id = Yii::app()->session["deviceId"];
$share_filter = MSharesFilter::init();
$share_filter->handlerCheckByFile($model['user_id'], $model);
if ($model['file_type'] == 0) {
$model['mime_type'] = MiniUtil::getMimeType($name);
//
// 如果是文件,需要创建版本
//
$user = Yii::app()->session['user'];
$device = UserDevice::model()->findByUserIdAndType($user['id'], CConst::DEVICE_WEB);
$deviceName = $device["user_device_name"];
$this->_saveFileMeta($path, $model['version_id'], $user['id'], $user['name'], CConst::CREATE_FILE, $deviceName, $model['file_size']);
} else {
//
// 文件夹需要更名所有子目录
//
$moreFile = UserFile::model()->findAll("file_path like :type", array('type' => $oldPath . '%'));
foreach ($moreFile as $key => $value) {
$data = date("Y-m-d H:i:s", time());
//
// 查找匹配路径 index, 替换路径
//
$index = strlen($oldPath);
$value['file_path'] = substr_replace($value['file_path'], $model['file_path'], 0, $index);
$s = UserFile::model()->updateAll(array('file_path' => $value['file_path'], 'file_update_time' => $time, 'updated_at' => $data), "id=" . $value['id']);
// 文件创建meta
if ($value['file_type'] == 0) {
//
// 如果是文件,需要创建版本
//
$user = Yii::app()->session['user'];
$device = UserDevice::model()->findByUserIdAndType($user['id'], CConst::DEVICE_WEB);
$deviceName = $device["user_device_name"];
$this->_saveFileMeta($value['file_path'], $value['version_id'], $user['id'], $user['name'], CConst::CREATE_FILE, $deviceName, $value['file_size']);
}
}
}
$user_id = $model['user_id'];
$event_uuid = MiniUtil::getEventRandomString(46);
$action = MConst::MOVE;
// 重命名
MiniEvent::getInstance()->createEvent($user_id, $device_id, $action, $oldPath, $context, $event_uuid, $share_filter->type);
//
// 重命名共享目录
//
if ($model['file_type'] >= 2) {
$share_filter->handlerRenameShared($oldPath, $context);
} else {
$share_filter->handlerAction($action, $device_id, $oldPath, $context);
}
$model['event_uuid'] = $event_uuid;
$message = Yii::t("admin_common", "rename_file_success");
return $model->save(false);
}
示例2: invoke
/**
*
* 外部调用入口
* @param bool $isParentId
*/
public function invoke($isParentId = true)
{
// TODO 应该使用path创建
$device = UserDevice::model()->find("user_id={$this->_userId} and user_device_type=1");
$this->_deviceId = $device["id"];
$this->_operator = $this->_userId;
//
// 空间检查
//
$this->handleSpace();
if ($this->_parentId == 0) {
$this->_path = "/{$this->_userId}/{$this->cname}";
} elseif ($isParentId) {
$parent = UserFile::model()->findByPk($this->_parentId);
if (empty($parent)) {
$this->handleResult(false, 3, "父目录不存在");
return;
}
if ($parent["file_type"] == 0) {
$this->handleResult(false, 3, "父目录不存在");
return;
}
$this->_path = $parent["file_path"] . "/" . $this->cname;
$this->_userId = $parent['user_id'];
} else {
$this->_path = "/{$this->_userId}/{$this->_path}";
}
//
// 命名检查
//
if (CUtils::checkNameInvalid($this->_path) != 0) {
$this->result["msg"] = "命名不能包含下列字符串: ^|?*\\<\":>";
return;
}
//
// 检查是否存在
//
$file = UserFile::model()->find(array('condition' => 'file_path=:file_path', 'params' => array(':file_path' => $this->_path)));
if ($file) {
if ($file["is_deleted"] == 0) {
$this->result["message"] = "文件夹已经存在";
return;
}
}
$this->_path = CUtils::convertStandardPath($this->_path);
//
// 共享检查
//
$index = strlen("/{$this->_userId}");
$path = substr_replace($this->_path, "", 0, $index);
if ($this->share_filter->handlerCheck($this->_userId, $path)) {
$this->_userId = $this->share_filter->master;
$this->_path = '/' . $this->_userId . $this->share_filter->_path;
}
$this->cid = $this->handleCreateByPath($this->_path);
$this->result["state"] = true;
$this->result["code"] = 0;
$this->result["message"] = "创建文件夹成功";
$this->result["cname"] = $this->cname;
$this->result['aid'] = $this->aid;
$this->result['cid'] = $this->cid;
}
示例3: invoke
/**
* move 执行入口
* @param bool $isPath - Use path to move if true ,or use id.
*/
public function invoke($isPath = true)
{
// 初始化入口
$device = new UserDevice();
$device = $device->findByUserIdAndType($this->_userId, CConst::DEVICE_WEB);
$this->_deviceId = $device["id"];
$this->_deviceName = $device["user_device_name"];
$user = User::model()->findByPk($this->_userId);
$this->_userNick = $user["user_name"];
$this->master = $this->_userId;
//
// 空间检查
//
$this->handleSpace();
if ($isPath) {
$this->fromPath = CUtils::convertStandardPath($this->fromPath);
$this->toPath = CUtils::convertStandardPath($this->toPath);
$this->initByPath();
} else {
$this->initById();
}
//
// 判断是否是共享
//
$from_share_filter = MSharesFilter::init();
$from_share_filter->handlerCheckByFile($this->_userId, $this->from);
$this->rename = false;
if ($from_share_filter->_is_shared_path && $this->toParent['id'] == 0) {
$this->rename = true;
} elseif ($from_share_filter->is_shared) {
$this->master = $from_share_filter->master;
$this->fromPath = '/' . $this->master . $from_share_filter->_path;
$this->from = UserFile::model()->findByAttributes(array('is_deleted' => 0, 'file_path' => $this->fromPath));
if (!$this->from) {
throw new ApiException("Not found");
}
}
//
// 检查移动原路径与目标路径是否一致,一致则返回成功
//
if ($this->fromPath === $this->toPath) {
$this->handleResult(false, 0, "已存在同名的文件");
return;
}
//
// 检查是否移动到其子目录下
//
if (strpos($this->toPath, $this->fromPath . "/") === 0) {
$this->result["msg"] = "不能移动到子目录";
return;
}
if ($this->toPath == "/{$this->_userId}" || $this->toPath == "/{$this->_userId}/") {
$this->result["msg"] = "目标目录不存在";
return;
}
//
// 命名检查
//
if (CUtils::checkNameInvalid($this->toPath) != 0 || CUtils::checkNameInvalid($this->toPath) != 0) {
$this->result["msg"] = "命名不能包含下列字符串: ^|?*\\<\":>";
return;
}
//
// 存在同名的则,拒绝
//
$target = UserFile::model()->findByAttributes(array("user_id" => $this->_userId, "file_path" => $this->toPath, "is_deleted" => 0));
if ($target) {
$this->handleResult(false, 0, "已存在同名的文件");
return;
}
$index = strlen("/{$this->from['user_id']}");
$fpath = substr_replace($this->fromPath, "", 0, $index);
$index = strlen("/{$this->toParent['user_id']}");
$tpath = substr_replace($this->toPath, "", 0, $index);
//
// 检查移动方式
//
if ($isPath == false && $this->rename == false && ($from_share_filter->handlerCheckMove($from_share_filter->master, $this->to_share_filter->master, $fpath, $tpath) || $this->to_share_filter->is_shared)) {
//
// 先copy再删除,如果是移动共享文件夹则只copy,再执行shareManager取消共享
//
$copy = new Copy();
$copy->_userId = $this->_userId;
$copy->toId = $this->toParent['id'];
$copy->fromId = $this->from['id'];
try {
$copy->invoke(false);
} catch (Exception $e) {
$this->result["msg"] = "操作失败";
return;
}
if ($this->from['file_type'] == 2 && $this->from['user_id'] != $this->to_share_filter->operator) {
$file_meta = FileMeta::model()->findByAttributes(array('meta_key' => 'shared_folders', 'file_path' => $this->from['file_path']));
if (!$file_meta) {
$this->result["msg"] = "操作失败";
return;
//.........这里部分代码省略.........