本文整理匯總了PHP中CUtils::removeUserFromPath方法的典型用法代碼示例。如果您正苦於以下問題:PHP CUtils::removeUserFromPath方法的具體用法?PHP CUtils::removeUserFromPath怎麽用?PHP CUtils::removeUserFromPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CUtils
的用法示例。
在下文中一共展示了CUtils::removeUserFromPath方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: buildResult
/**
* 處理返回值
*/
public function buildResult($query_db_file, $to_path = null)
{
// 處理不同端,不同返回值
if (MUserManager::getInstance()->isWeb() === true) {
$this->buildWebResponse();
return;
}
if ($this->isEcho === false) {
return;
}
$is_dir = true;
$size = $query_db_file["file_size"];
$response = array();
if ($query_db_file["file_type"] == MConst::OBJECT_TYPE_FILE) {
// 根據文件名後綴判斷mime type
$mime_type = MiniUtil::getMimeType($query_db_file["file_name"]);
$is_dir = false;
$response["mime_type"] = $mime_type;
$response["thumb_exists"] = MUtils::isExistThumbnail($mime_type, (int) $query_db_file["file_size"]);
}
// 去除/{user_id}
$path = CUtils::removeUserFromPath($query_db_file["file_path"]);
$response["size"] = MUtils::getSizeByLocale($this->_locale, $size);
$response["is_deleted"] = false;
$response["bytes"] = intval($size);
$response["modified"] = MUtils::formatIntTime($query_db_file["file_update_time"]);
if ($to_path) {
$path = $to_path;
} else {
$path = $query_db_file["file_path"];
}
$path_info = MUtils::pathinfo_utf($path);
$path_info_out = MUtils::pathinfo_utf($this->to_share_filter->src_path);
$path = MUtils::convertStandardPath($path_info_out['dirname'] . "/" . $path_info['basename']);
$response["path"] = $path;
$response["root"] = $this->_root;
$response["is_dir"] = $is_dir;
$response["rev"] = strval($query_db_file["version_id"]);
$response["revision"] = intval($query_db_file["version_id"]);
// 增加操作返回事件編碼
$response["event_uuid"] = $query_db_file["event_uuid"];
echo json_encode($response);
}
示例2: downloadToPackage
//.........這裏部分代碼省略.........
}
if (count($fileNames) > 1) {
$packageName = 'miniyun';
} else {
$packageName = $fileNames[0];
}
//創建臨時文件夾
$fileSystem = new CFileSystem();
MUtils::MkDirsLocal(DOCUMENT_TEMP . $userId);
$storePath = DOCUMENT_TEMP . $userId . "/" . $packageName;
$array = array();
$ids = explode(",", $code);
foreach ($ids as $id) {
$file = MiniFile::getInstance()->getById($id);
if (empty($file)) {
continue;
}
if ($file["file_type"] == MConst::OBJECT_TYPE_FILE) {
//屬於自己的文件
$array[] = $file;
} else {
//不屬於自己的文件
//查詢共有多少個子目錄
$array[] = $file;
$files = MiniFile::getInstance()->getChildrenByPath($file["file_path"]);
$array = array_merge($array, $files);
}
}
if (count($array) > $limitCount) {
echo "批量下載單次最大文件數不能超過:" . $limitCount;
exit;
}
$size = $this->calculateSize($array);
if ($size > $limitSize * 1024 * 1024) {
echo "批量下載單次最大文件大小不能超過:" . $limitSize . "M";
exit;
}
$path = CUtils::removeUserFromPath($array[0]["file_path"]);
$removeParent = pathinfo($path, PATHINFO_DIRNAME);
if (strlen($removeParent) == 1) {
$removeParent = "";
}
//zip壓縮
$zip = new ZipArchive();
$zipFile = $storePath . ".zip";
//刪除上次存在的壓縮文件
$fileSystem->delete($zipFile);
try {
$zipFile = mb_convert_encoding($zipFile, "gb2312", "UTF-8");
} catch (Exception $e) {
$zipFile = $zipFile;
}
if ($zip->open($zipFile, ZIPARCHIVE::OVERWRITE) === TRUE) {
//執行拷貝操作
foreach ($array as $file) {
$fileType = $file["file_type"];
$filePath = $file["file_path"];
//獲取存儲文件的絕對路徑
if (!empty($removeParent)) {
$relativePath = CUtils::str_replace_once($removeParent, "", CUtils::removeUserFromPath($filePath));
} else {
$relativePath = CUtils::removeUserFromPath($filePath);
}
//打包加上nick
$relativePath = $packageName . $relativePath;
//轉換文件編碼為中文編碼
try {
$store = mb_convert_encoding($relativePath, "gb2312", "UTF-8");
} catch (Exception $e) {
$store = $relativePath;
}
$hasRead = true;
if ($userId == $file["user_id"] && $fileType == MConst::OBJECT_TYPE_FILE) {
//屬於自己的文件
$this->addToFile($zip, $file, $store, $fileSystem);
} elseif ($userId != $file["user_id"] && $fileType == MConst::OBJECT_TYPE_FILE) {
//不屬於自己的文件
if ($hasRead) {
$this->addToFile($zip, $file, $store, $fileSystem);
}
} elseif ($userId == $file["user_id"] && $fileType == MConst::OBJECT_TYPE_DIRECTORY) {
//屬於自己的文件夾
$this->addToFolder($zip, $store);
} else {
//不屬於自己的文件夾
if ($hasRead) {
$this->addToFolder($zip, $store);
}
}
}
$zip->close();
//關閉
}
if (!file_exists($zipFile)) {
echo Yii::t('i18n', 'no_privilege');
Yii::app()->end();
}
//進行下載
CUtils::output($zipFile, "application/octet-stream", $packageName . ".zip");
}
示例3: invoke
/**
* 控製器執行主邏輯函數, 複製文件或者文件夾
*/
public function invoke($uri = null)
{
$this->setAction(MConst::COPY);
$this->beforeInvoke();
$this->beforecheck();
$user = MUserManager::getInstance()->getCurrentUser();
// 調用父類初始化函數,注冊自定義的異常和錯誤處理邏輯
parent::init();
$params = $_REQUEST;
// 檢查參數
if (isset($params) === false) {
throw new MFileopsException(Yii::t('api', 'Bad Request 11'), MConst::HTTP_CODE_400);
}
// 文件大小格式化參數
$locale = "bytes";
if (isset($params["root"]) === false || isset($params["from_path"]) === false || isset($params["to_path"]) === false) {
throw new MFileopsException(Yii::t('api', 'Bad Request 12'), MConst::HTTP_CODE_400);
}
if (isset($params["locale"])) {
$locale = $params["locale"];
}
$root = $params["root"];
$this->_from_path = $params["from_path"];
$this->_to_path = $params["to_path"];
if ($params['is_root']) {
$this->_to_path = '/' . $user['id'] . $this->_to_path;
}
//
// 檢查文件名是否有效
//
$isInvalid = MUtils::checkNameInvalid(MUtils::get_basename($this->_to_path));
if ($isInvalid) {
throw new MFileopsException(Yii::t('api', 'Bad Request 13'), MConst::HTTP_CODE_400);
}
//
// 轉換路徑分隔符,便於以後跨平台,如:將 "\"=>"/"
//
$this->_from_path = MUtils::convertStandardPath($this->_from_path);
$this->_to_path = MUtils::convertStandardPath($this->_to_path);
if ($this->_from_path == "/" || $this->_to_path == "/" || $this->_from_path === false || $this->_to_path === false) {
throw new MFileopsException(Yii::t('api', 'Bad Request 14'), MConst::HTTP_CODE_400);
}
if ($this->_to_path[strlen($this->_to_path) - 1] == "/") {
// 目標文件無效,403 error
throw new Exception(Yii::t('api', 'The file or folder name is invalid'), MConst::HTTP_CODE_403);
}
//
// 檢查共享
//
$from_share_filter = MSharesFilter::init();
$this->to_share_filter = MSharesFilter::init();
// 當從共享目錄拷貝到其他目錄時,源目錄用戶id設置為共享用戶id
// if ($from_share_filter->handlerCheck($this->owner, $this->_from_path)) {
// $this->master = $from_share_filter->master;
// $this->_from_path = $from_share_filter->_path;
// }
//
// // 當拷貝到共享目錄的時候,目標目錄的用戶id設置為共享用戶id
// if ($this->to_share_filter->handlerCheck($this->_user_id, $this->_to_path)) {
// $this->_user_id = $this->to_share_filter->master;
// $this->user_nick = $this->to_share_filter->master_nick;
// $this->_to_path = $this->to_share_filter->_path;
// }
// if($this->_from_shared_path){
// $this->_from_path = $this->_from_shared_path;
// }else{
// $this->_from_path = "/".$this->master.$this->_from_path;
// }
// if($this->_to_shared_path){
// $this->_to_path = $this->_to_shared_path;
// }else{
// $this->_to_path = "/".$this->_user_id.$this->_to_path;
// }
//
// 檢查目標路徑是否在複製目錄下
//
if (strpos($this->_to_path, $this->_from_path . "/") === 0) {
throw new MFileopsException(Yii::t('api', 'Can not be copied to the subdirectory'), MConst::HTTP_CODE_403);
}
$check = CUtils::removeUserFromPath($this->_to_path);
if (empty($check) || $check == '/') {
throw new MFileopsException(Yii::t('api', 'Can not be copied to the error directory'), MConst::HTTP_CODE_403);
}
//
// 檢查目標路徑文件是否存在
//
$queryToPathDbFile = MFiles::queryAllFilesByPath($this->_to_path);
$isUpdate = false;
if ($queryToPathDbFile) {
if ($queryToPathDbFile[0]["is_deleted"] == false) {
// 已經存在,403 error
throw new MFileopsException(Yii::t('api', 'There is already a item at the given destination'), MConst::HTTP_CODE_403);
}
$isUpdate = true;
}
//
// 查詢其信息
//.........這裏部分代碼省略.........
示例4: invoke
//.........這裏部分代碼省略.........
$privilegeModel = new PrivilegeBiz();
$share_filter->slaves = $privilegeModel->getSlaveIdsByPath($permissionArr['share_root_path']);
$share_filter->is_shared = true;
if ($file_detail->file_type == 0) {
//刪除文件
$can_file_delete = substr($permission, 7, 1);
if ($can_file_delete == 0) {
throw new MFileopsException(Yii::t('api', 'no permission'), MConst::HTTP_CODE_409);
}
}
if ($file_detail->file_type == 1 || $file_detail->file_type == 2 || $file_detail->file_type == 4) {
$can_folder_delete = substr($permission, 3, 1);
if ($can_folder_delete == 0) {
throw new MFileopsException(Yii::t('api', 'no permission'), MConst::HTTP_CODE_409);
}
}
}
}
//
// 更新文件元數據的為刪除數據
//
$this->assembleFileDetail($file_detail, $query_db_file[0]);
$ret_value = MFiles::updateRemoveFileDetail($file_detail);
if ($ret_value === false) {
throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
}
//
// 將刪除目錄加入數組
//
array_push($files, $file_detail);
//
// 保存事件
//
$ret_value = MiniEvent::getInstance()->createEvents($this->_user_id, $user_device_id, $files, $share_filter->type);
if ($ret_value === false) {
throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
}
//
//
//
if ($share_filter->is_shared) {
foreach ($files as $file) {
$share_filter->handlerAction($file->event_action, $user_device_id, $file->from_path, $file->context);
}
}
//
// 刪除共享目錄(刪除共享目錄,對應的權限也一起刪除)
//
//首先判斷用戶有無刪除權限
$userPrivilegeList = MiniUserPrivilege::getInstance()->getPrivilegeList($file_detail->file_path);
$groupPrivilegeList = MiniGroupPrivilege::getInstance()->getPrivilegeList($file_detail->file_path);
if (!empty($userPrivilegeList)) {
MiniUserPrivilege::getInstance()->deleteByFilePath($file_detail->file_path);
}
if (!empty($groupPrivilegeList)) {
MiniGroupPrivilege::getInstance()->deleteByFilePath($file_detail->file_path);
}
//並且將file_type改為1
if ($file_detail->file_type == 0) {
MiniFile::getInstance()->togetherShareFile($file_detail->file_path, Mconst::OBJECT_TYPE_FILE);
} else {
MiniFile::getInstance()->togetherShareFile($file_detail->file_path, Mconst::OBJECT_TYPE_DIRECTORY);
}
if ($filter !== true && $share_filter->_is_shared_path && $share_filter->operator == $share_filter->master) {
$file = MFiles::queryFilesByPath("/" . $share_filter->operator . $path, true);
if (!$file) {
throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
}
$id = $file[0]["id"];
$handler = new ShareManager();
$handler->_userId = $share_filter->operator;
$handler->_id = $id;
try {
$handler->invoke(ShareManager::CANCEL_SHARED);
} catch (Exception $e) {
throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
}
}
// 如果徹底刪除,則調用回收站
if ($this->completely_remove) {
$trash = new Trash();
$trash->_userId = $this->_user_id;
$trash->fromIds = $file_detail->id;
try {
$trash->invoke(Trash::DELETE);
} catch (Exception $e) {
throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
}
//執行的額外操作
$this->extend($share_filter, $query_db_file, $file_detail);
return;
}
$path = CUtils::removeUserFromPath($query_db_file[0]["file_path"]);
$path_info = MUtils::pathinfo_utf($path);
$path_info_out = MUtils::pathinfo_utf($share_filter->src_path);
$path = MUtils::convertStandardPath($path_info_out['dirname'] . "/" . $path_info['basename']);
//執行的額外操作
$this->extend($share_filter, $query_db_file, $file_detail);
$this->buildResult($root, $path, $query_db_file[0]["version_id"], $query_db_file[0]["file_update_time"], $file_detail->is_dir);
}
示例5: handleDelete
/**
*
* 刪除回收站一條記錄
*
* @since 1.0.7
*/
private function handleDelete()
{
if ($this->fromIds == "-1") {
throw new ApiException(Yii::t('common', 'param_error'));
}
// 獲取文件(夾)信息
$files = UserFile::model()->getFilesByIds($this->fromIds, 1);
// 我的最愛和分享都刪除
// FileStar::model()->deleteAllByFileIds($this->_userId, $this->fromIds);
FileStar::model()->deleteAll('id in (:ids)', array(':ids' => $this->fromIds));
MiniLink::getInstance()->unlink($this->fromIds);
$publicFilter = MSharesFilter::init();
// 如果是文件,則直接刪除,否則刪除文件夾下子文件
foreach ($files as $file) {
//先進行回收站刪除權限的判斷
$file_path = CUtils::removeUserFromPath($file["file_path"]);
if ($publicFilter->handlerCheck($this->_userId, $file_path)) {
$this->_userId = $publicFilter->master;
$path = $publicFilter->_path;
}
if ($publicFilter->is_shared && $publicFilter->master != $publicFilter->operator) {
//如果沒有讀權限則不進行刪除
$permission = Yii::app()->privilege->checkPrivilege('/' . $publicFilter->master . $path);
if (!$permission[MPrivilege::RESOURCE_READ]) {
continue;
}
if ($file["file_type"] == 0 && !$permission[MPrivilege::FILE_DELETE]) {
continue;
} elseif (!$permission[MPrivilege::FOLDER_DELETE]) {
continue;
}
}
if ($file["file_type"] == 0) {
MiniVersion::getInstance()->updateRefCount($file['version_id'], FALSE);
$file->delete();
continue;
}
$parentPath = $file["file_path"];
$children = UserFile::model()->getFilesByPath($parentPath, 1);
foreach ($children as $child) {
if ($child["file_type"] == 0) {
MiniVersion::getInstance()->updateRefCount($child['version_id'], FALSE);
}
$child->delete();
}
$file->delete();
}
$this->handleResult(TRUE, 0, Yii::t('api_message', 'action_success'));
}
示例6: createPrivelegeEvent
/**
*
* 添加事件
*
* @since 1.0.7
*/
public function createPrivelegeEvent($user_id, $file_path, $permission)
{
//如果是自己則排除
$own_user_id = CUtils::getUserFromPath($file_path);
if ($own_user_id == $user_id) {
return;
}
//默認的權限
$defaultPermission = Yii::app()->privilege->getFilePrivilegeDefault($file_path);
$file_path = '/' . $user_id . CUtils::removeUserFromPath($file_path);
$content = $file_path;
if ($permission[MPrivilege::RESOURCE_READ] && !$defaultPermission[MPrivilege::RESOURCE_READ]) {
//當默認權限為不能讀,現在變更為能讀
$this->createEvent($user_id, MConst::CAN_READ, $file_path, $content);
} elseif (!$permission[MPrivilege::RESOURCE_READ] && $defaultPermission[MPrivilege::RESOURCE_READ]) {
//當默認權限為能讀 現在變更為不能讀
$this->createEvent($user_id, MConst::CAN_NOT_READ, $file_path, $content);
}
}
示例7: invoke
//.........這裏部分代碼省略.........
if ($path == false) {
throw new MFileopsException(Yii::t('api', 'The folder name is invalid'), MConst::HTTP_CODE_400);
}
// 檢查是否在共享目錄
$this->share_filter = MSharesFilter::init();
if ($this->share_filter->handlerCheck($this->_user_id, $path, MConst::CREATE_DIRECTORY)) {
$this->_user_id = $this->share_filter->master;
$path = $this->share_filter->_path;
}
if ($params['is_root'] == "/") {
$path = "/" . $this->_user_id . $path;
}
$item = explode("/", $path);
if (!preg_match("/^[0-9]+\$/", $item[1])) {
$path = "/" . $user["user_id"] . $path;
}
$parentPath = dirname($path);
$isSharedPath = false;
//主要用於判斷是否為被共享文件
if (dirname(MiniUtil::getRelativePath($path)) == "/" . $this->_user_id) {
$permission = MConst::SUPREME_PERMISSION;
} else {
$pathArr = explode('/', $path);
$masterId = $pathArr[1];
if ($masterId != $this->_user_id) {
$isSharedPath = true;
} else {
$model = new GeneralFolderPermissionBiz($parentPath);
if ($model->isParentShared($parentPath)) {
//如果是父目錄被共享
$isSharedPath = true;
}
}
if ($isSharedPath) {
$permissionArr = UserPermissionBiz::getInstance()->getPermission($parentPath, $this->_user_id);
if (!isset($permissionArr)) {
$permission = MConst::SUPREME_PERMISSION;
} else {
$permission = $permissionArr['permission'];
$privilegeModel = new PrivilegeBiz();
$this->share_filter->slaves = $privilegeModel->getSlaveIdsByPath($permissionArr['share_root_path']);
$this->share_filter->is_shared = true;
}
} else {
$permission = MConst::SUPREME_PERMISSION;
}
}
$miniPermission = new MiniPermission($permission);
$canCreateFolder = $miniPermission->canCreateFolder();
if (!$canCreateFolder) {
throw new MFileopsException(Yii::t('api', 'no permission'), MConst::HTTP_CODE_409);
}
// 查詢其是否存在 信息
$file = MiniFile::getInstance()->getByPath($path);
// 是否存在相同文件路徑, 且被刪除的記錄
$hadFileDelete = false;
if (isset($file)) {
if ($file["is_deleted"] == false) {
$code = $file["file_type"] == MConst::OBJECT_TYPE_FILE ? MConst::HTTP_CODE_402 : MConst::HTTP_CODE_403;
if (MUserManager::getInstance()->isWeb() === true) {
throw new MFileopsException(Yii::t('api', 'There is already a item at the given destination'), $code);
}
$uuid = $file["event_uuid"];
// 已經存在,403 error
throw new MFileopsException($code);
}
$hadFileDelete = true;
}
$this->_parentFilePath = "/{$this->_user_id}";
// 檢查父目錄
$parentFileId = $this->handlerParentFolder($parentPath);
$fileDetail = $this->createFile($path, $parentFileId, $hadFileDelete);
// 處理不同端,不同返回值
if (MUserManager::getInstance()->isWeb() === true) {
if ($this->isOutput) {
$this->buildWebResponse($fileName, $path);
}
return;
}
$response = array();
$response["size"] = "0";
$response["thumb_exists"] = false;
$response["bytes"] = 0;
$response["modified"] = MUtils::formatIntTime($fileDetail["file_update_time"]);
$path = CUtils::removeUserFromPath("{$this->_parentFilePath}/{$fileName}");
if ($this->share_filter->is_shared) {
$path = $this->share_filter->src_path;
$path_info = MUtils::pathinfo_utf($path);
$path = MUtils::convertStandardPath($path_info['dirname'] . "/" . $fileName);
}
$response["path"] = $this->_parentFilePath . "/" . $fileName;
$response["is_dir"] = true;
$response["icon"] = "folder";
$response["root"] = $root;
$response["revision"] = 0;
// 版本
// 增加返回事件uuid,便於客戶端進行事件對比邏輯
$response["event_uuid"] = $fileDetail["event_uuid"];
echo json_encode($response);
}