本文整理汇总了PHP中OC_Filesystem::normalizePath方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Filesystem::normalizePath方法的具体用法?PHP OC_Filesystem::normalizePath怎么用?PHP OC_Filesystem::normalizePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Filesystem
的用法示例。
在下文中一共展示了OC_Filesystem::normalizePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: put
/**
* put filesystem info in the cache
* @param string $path
* @param array data
* @param string root (optional)
* @note $data is an associative array in the same format as returned
* by get
*/
public static function put($path, $data, $root = false)
{
if ($root === false) {
$root = OC_Filesystem::getRoot();
}
$fullpath = OC_Filesystem::normalizePath($root . '/' . $path);
$parent = self::getParentId($fullpath);
$id = self::getId($fullpath, '');
if (isset(OC_FileCache_Cached::$savedData[$fullpath])) {
$data = array_merge(OC_FileCache_Cached::$savedData[$fullpath], $data);
unset(OC_FileCache_Cached::$savedData[$fullpath]);
}
if ($id != -1) {
self::update($id, $data);
return;
}
// add parent directory to the file cache if it does not exist yet.
if ($parent == -1 && $fullpath != $root) {
$parentDir = dirname($path);
self::scanFile($parentDir);
$parent = self::getParentId($fullpath);
}
if (!isset($data['size']) or !isset($data['mtime'])) {
//save incomplete data for the next time we write it
OC_FileCache_Cached::$savedData[$fullpath] = $data;
return;
}
if (!isset($data['encrypted'])) {
$data['encrypted'] = false;
}
if (!isset($data['versioned'])) {
$data['versioned'] = false;
}
$mimePart = dirname($data['mimetype']);
$data['size'] = (int) $data['size'];
$data['ctime'] = (int) $data['mtime'];
$data['writable'] = (int) $data['writable'];
$data['encrypted'] = (int) $data['encrypted'];
$data['versioned'] = (int) $data['versioned'];
$user = OC_User::getUser();
$query = OC_DB::prepare('INSERT INTO `*PREFIX*fscache`(`parent`, `name`, `path`, `path_hash`, `size`, `mtime`, `ctime`, `mimetype`, `mimepart`,`user`,`writable`,`encrypted`,`versioned`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)');
$result = $query->execute(array($parent, basename($fullpath), $fullpath, md5($fullpath), $data['size'], $data['mtime'], $data['ctime'], $data['mimetype'], $mimePart, $user, $data['writable'], $data['encrypted'], $data['versioned']));
if (OC_DB::isError($result)) {
OC_Log::write('files', 'error while writing file(' . $fullpath . ') to cache', OC_Log::ERROR);
}
if ($cache = OC_Cache::getUserCache(true)) {
$cache->remove('fileid/' . $fullpath);
//ensure we don't have -1 cached
}
}
示例2: getDirectoryContent
/**
* get the content of a directory
* @param dir $directory path under datadirectory
*/
public static function getDirectoryContent($directory, $mimetype_filter = '')
{
$directory = OC_Filesystem::normalizePath($directory);
if ($directory == '/') {
$directory = '';
}
$files = array();
if (($directory == '/Shared' || substr($directory, 0, 8) == '/Shared/') && OC_App::isEnabled('files_sharing')) {
if ($directory == '/Shared') {
$files = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP, array('folder' => $directory, 'mimetype_filter' => $mimetype_filter));
} else {
$pos = strpos($directory, '/', 8);
// Get shared folder name
if ($pos !== false) {
$itemTarget = substr($directory, 7, $pos - 7);
} else {
$itemTarget = substr($directory, 7);
}
$files = OCP\Share::getItemSharedWith('folder', $itemTarget, OC_Share_Backend_File::FORMAT_FILE_APP, array('folder' => $directory, 'mimetype_filter' => $mimetype_filter));
}
} else {
$files = OC_FileCache::getFolderContent($directory, false, $mimetype_filter);
foreach ($files as &$file) {
$file['directory'] = $directory;
$file['type'] = $file['mimetype'] == 'httpd/unix-directory' ? 'dir' : 'file';
$permissions = OCP\PERMISSION_READ;
// NOTE: Remove check when new encryption is merged
if (!$file['encrypted']) {
$permissions |= OCP\PERMISSION_SHARE;
}
if ($file['type'] == 'dir' && $file['writable']) {
$permissions |= OCP\PERMISSION_CREATE;
}
if ($file['writable']) {
$permissions |= OCP\PERMISSION_UPDATE | OCP\PERMISSION_DELETE;
}
$file['permissions'] = $permissions;
}
if ($directory == '' && OC_App::isEnabled('files_sharing')) {
// Add 'Shared' folder
$files = array_merge($files, OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP_ROOT));
}
}
usort($files, "fileCmp");
//TODO: remove this once ajax is merged
return $files;
}
示例3: preFile_put_contents
/**
* @param $path
* @param $data
* @return bool
*/
public function preFile_put_contents($path, &$data)
{
if (self::shouldEncrypt($path)) {
if (!is_resource($data)) {
// get root view
$view = new \OC_FilesystemView('/');
// get relative path
$relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path);
if (!isset($relativePath)) {
return true;
}
// create random cache folder
$cacheFolder = rand();
$path_slices = explode('/', \OC_Filesystem::normalizePath($path));
$path_slices[2] = "cache/" . $cacheFolder;
$tmpPath = implode('/', $path_slices);
$handle = fopen('crypt://' . $tmpPath, 'w');
if (is_resource($handle)) {
// write data to stream
fwrite($handle, $data);
// close stream
fclose($handle);
// disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
// get encrypted content
$data = $view->file_get_contents($tmpPath);
// remove our temp file
$view->deleteAll('/' . \OCP\User::getUser() . '/cache/' . $cacheFolder);
// re-enable proxy - our work is done
\OC_FileProxy::$enabled = $proxyStatus;
}
}
}
return true;
}
示例4: file_assemble
public function file_assemble($path)
{
$absolutePath = OC_Filesystem::normalizePath(OC_Filesystem::getView()->getAbsolutePath($path));
$data = '';
// use file_put_contents as method because that best matches what this function does
if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) && OC_Filesystem::isValidPath($path)) {
$path = OC_Filesystem::getView()->getRelativePath($absolutePath);
$exists = OC_Filesystem::file_exists($path);
$run = true;
if (!$exists) {
OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, array(OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
}
OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, array(OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
if (!$run) {
return false;
}
$target = OC_Filesystem::fopen($path, 'w');
if ($target) {
$count = $this->assemble($target);
fclose($target);
if (!$exists) {
OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_create, array(OC_Filesystem::signal_param_path => $path));
}
OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array(OC_Filesystem::signal_param_path => $path));
OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
return $count > 0;
} else {
return false;
}
}
}
示例5: postFile_put_contents
/**
* @brief update file cache with the new unencrypted size after file was written
* @param string $path
* @param mixed $result
* @return mixed
*/
public function postFile_put_contents($path, $result)
{
$normalizedPath = \OC_Filesystem::normalizePath($path);
if (isset(self::$unencryptedSizes[$normalizedPath])) {
$view = new \OC_FilesystemView('/');
$view->putFileInfo($normalizedPath, array('encrypted' => true, 'unencrypted_size' => self::$unencryptedSizes[$normalizedPath]));
unset(self::$unencryptedSizes[$normalizedPath]);
}
return $result;
}
示例6: min
$list->assign('downloadURL', OCP\Util::linkTo('files', 'download.php') . '?file=', false);
$breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
$breadcrumbNav->assign('breadcrumb', $breadcrumb, false);
$breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '&dir=', false);
$upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize'));
$post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
$maxUploadFilesize = min($upload_max_filesize, $post_max_size);
$freeSpace = OC_Filesystem::free_space('/');
$freeSpace = max($freeSpace, 0);
$maxUploadFilesize = min($maxUploadFilesize, $freeSpace);
$permissions = OCP\Share::PERMISSION_READ;
if (OC_Filesystem::isUpdatable($dir . '/')) {
$permissions |= OCP\Share::PERMISSION_UPDATE;
}
if (OC_Filesystem::isDeletable($dir . '/')) {
$permissions |= OCP\Share::PERMISSION_DELETE;
}
if (OC_Filesystem::isSharable($dir . '/')) {
$permissions |= OCP\Share::PERMISSION_SHARE;
}
$tmpl = new OCP\Template('files', 'index', 'user');
$tmpl->assign('fileList', $list->fetchPage(), false);
$tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage(), false);
$tmpl->assign('dir', OC_Filesystem::normalizePath($dir));
$tmpl->assign('isCreatable', OC_Filesystem::isCreatable($dir . '/'));
$tmpl->assign('permissions', $permissions);
$tmpl->assign('files', $files);
$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
$tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
$tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
$tmpl->printPage();
示例7: correctPath
/**
* @brief make sure that the path has the correct root
*
* @param string $path path returned from the share API
* @param string $folder current root folder
* @return string the correct path
*/
protected static function correctPath($path, $folder)
{
return \OC_Filesystem::normalizePath('/' . $folder . '/' . basename($path));
}
示例8: getItems
//.........这里部分代码省略.........
$queryArgs[] = self::$shareTypeGroupUserUnique;
}
if ($itemType == 'file' || $itemType == 'folder') {
$column = 'file_source';
} else {
$column = 'item_source';
}
} else {
if ($itemType == 'file' || $itemType == 'folder') {
$column = 'file_target';
} else {
$column = 'item_target';
}
}
if (isset($item)) {
if ($includeCollections && ($collectionTypes = self::getCollectionItemTypes($itemType))) {
$where .= ' AND (';
} else {
$where .= ' AND';
}
// If looking for own shared items, check item_source else check item_target
if (isset($uidOwner) || $itemShareWithBySource) {
// If item type is a file, file source needs to be checked in case the item was converted
if ($itemType == 'file' || $itemType == 'folder') {
$where .= ' `file_source` = ?';
$column = 'file_source';
} else {
$where .= ' `item_source` = ?';
$column = 'item_source';
}
} else {
if ($itemType == 'file' || $itemType == 'folder') {
$where .= ' `file_target` = ?';
$item = \OC_Filesystem::normalizePath($item);
} else {
$where .= ' `item_target` = ?';
}
}
$queryArgs[] = $item;
if ($includeCollections && $collectionTypes) {
$placeholders = join(',', array_fill(0, count($collectionTypes), '?'));
$where .= ' OR item_type IN (' . $placeholders . '))';
$queryArgs = array_merge($queryArgs, $collectionTypes);
}
}
if ($limit != -1 && !$includeCollections) {
if ($shareType == self::$shareTypeUserAndGroups) {
// Make sure the unique user target is returned if it exists, unique targets should follow the group share in the database
// If the limit is not 1, the filtering can be done later
$where .= ' ORDER BY `*PREFIX*share`.`id` DESC';
}
// The limit must be at least 3, because filtering needs to be done
if ($limit < 3) {
$queryLimit = 3;
} else {
$queryLimit = $limit;
}
} else {
$queryLimit = null;
}
// TODO Optimize selects
if ($format == self::FORMAT_STATUSES) {
if ($itemType == 'file' || $itemType == 'folder') {
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `file_source`, `path`, `expiration`';
} else {
$select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`';
示例9: createMissingDirectories
/**
* @brief create recursively missing directories
* @param string $filename $path to a file
* @param \OC\Files\View $view view on data/user/
*/
private static function createMissingDirectories($filename, $view)
{
$dirname = \OC_Filesystem::normalizePath(dirname($filename));
$dirParts = explode('/', $dirname);
$dir = "/files_versions";
foreach ($dirParts as $part) {
$dir = $dir . '/' . $part;
if (!$view->file_exists($dir)) {
$view->mkdir($dir);
}
}
}
示例10: array
}
}
break;
}
}
if ($source) {
if (substr($source, 0, 8) != 'https://' and substr($source, 0, 7) != 'http://') {
OCP\JSON::error(array("data" => array("message" => "Not a valid source")));
exit;
}
$ctx = stream_context_create(null, array('notification' => 'progress'));
$sourceStream = fopen($source, 'rb', false, $ctx);
$target = $dir . '/' . $filename;
$result = OC_Filesystem::file_put_contents($target, $sourceStream);
if ($result) {
$target = OC_Filesystem::normalizePath($target);
$meta = OC_FileCache::get($target);
$mime = $meta['mimetype'];
$id = OC_FileCache::getId($target);
$eventSource->send('success', array('mime' => $mime, 'size' => OC_Filesystem::filesize($target), 'id' => $id));
} else {
$eventSource->send('error', "Error while downloading " . $source . ' to ' . $target);
}
$eventSource->close();
exit;
} else {
if ($content) {
if (OC_Filesystem::file_put_contents($dir . '/' . $filename, $content)) {
$meta = OC_FileCache::get($dir . '/' . $filename);
$id = OC_FileCache::getId($dir . '/' . $filename);
OCP\JSON::success(array("data" => array('content' => $content, 'id' => $id)));
示例11: dummyHook
public function dummyHook($arguments)
{
$path = $arguments['path'];
$this->assertEqual($path, OC_Filesystem::normalizePath($path));
//the path passed to the hook should already be normalized
}
示例12: mkdirr
/**
* @brief create directory recursively
* @param string $path
* @param \OC\Files\View $view
*/
public static function mkdirr($path, $view)
{
$dirname = \OC_Filesystem::normalizePath(dirname($path));
$dirParts = explode('/', $dirname);
$dir = "";
foreach ($dirParts as $part) {
$dir = $dir . '/' . $part;
if (!$view->file_exists($dir)) {
$view->mkdir($dir);
}
}
}
示例13: getUidAndFilename
/**
* @brief get uid of the owners of the file and the path to the file
* @param string $path Path of the file to check
* @throws \Exception
* @note $shareFilePath must be relative to data/UID/files. Files
* relative to /Shared are also acceptable
* @return array
*/
public function getUidAndFilename($path)
{
$pathinfo = pathinfo($path);
$partfile = false;
$parentFolder = false;
if (array_key_exists('extension', $pathinfo) && $pathinfo['extension'] === 'part') {
// if the real file exists we check this file
$filePath = $this->userFilesDir . '/' . $pathinfo['dirname'] . '/' . $pathinfo['filename'];
if ($this->view->file_exists($filePath)) {
$pathToCheck = $pathinfo['dirname'] . '/' . $pathinfo['filename'];
} else {
// otherwise we look for the parent
$pathToCheck = $pathinfo['dirname'];
$parentFolder = true;
}
$partfile = true;
} else {
$pathToCheck = $path;
}
$view = new \OC\Files\View($this->userFilesDir);
$fileOwnerUid = $view->getOwner($pathToCheck);
// handle public access
if ($this->isPublic) {
$filename = $path;
$fileOwnerUid = $this->userId;
return array($fileOwnerUid, $filename);
} else {
// Check that UID is valid
if (!\OCP\User::userExists($fileOwnerUid)) {
throw new \Exception('Could not find owner (UID = "' . var_export($fileOwnerUid, 1) . '") of file "' . $path . '"');
}
// NOTE: Bah, this dependency should be elsewhere
\OC\Files\Filesystem::initMountPoints($fileOwnerUid);
// If the file owner is the currently logged in user
if ($fileOwnerUid === $this->userId) {
// Assume the path supplied is correct
$filename = $path;
} else {
$info = $view->getFileInfo($pathToCheck);
$ownerView = new \OC\Files\View('/' . $fileOwnerUid . '/files');
// Fetch real file path from DB
$filename = $ownerView->getPath($info['fileid']);
if ($parentFolder) {
$filename = $filename . '/' . $pathinfo['filename'];
}
if ($partfile) {
$filename = $filename . '.' . $pathinfo['extension'];
}
}
return array($fileOwnerUid, \OC_Filesystem::normalizePath($filename));
}
}
示例14: basicOperation
/**
* @brief abstraction layer for basic filesystem functions: wrapper for OC_Filestorage
* @param string $operation
* @param string #path
* @param array (optional) hooks
* @param mixed (optional) $extraParam
* @return mixed
*
* This method takes requests for basic filesystem functions (e.g. reading & writing
* files), processes hooks and proxies, sanitises paths, and finally passes them on to
* OC_Filestorage for delegation to a storage backend for execution
*/
private function basicOperation($operation, $path, $hooks = array(), $extraParam = null)
{
$postFix = substr($path, -1, 1) === '/' ? '/' : '';
$absolutePath = OC_Filesystem::normalizePath($this->getAbsolutePath($path));
if (OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)) {
$path = $this->getRelativePath($absolutePath);
if ($path == null) {
return false;
}
$internalPath = $this->getInternalPath($path . $postFix);
$run = $this->runHooks($hooks, $path);
if ($run and $storage = $this->getStorage($path . $postFix)) {
if (!is_null($extraParam)) {
$result = $storage->{$operation}($internalPath, $extraParam);
} else {
$result = $storage->{$operation}($internalPath);
}
$result = OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);
if (OC_Filesystem::$loaded and $this->fakeRoot == OC_Filesystem::getRoot()) {
if ($operation != 'fopen') {
//no post hooks for fopen, the file stream is still open
$this->runHooks($hooks, $path, true);
}
}
return $result;
}
}
return null;
}
示例15: getUidAndFilename
/**
* @brief get uid of the owners of the file and the path to the file
* @param string $path Path of the file to check
* @throws \Exception
* @note $shareFilePath must be relative to data/UID/files. Files
* relative to /Shared are also acceptable
* @return array
*/
public function getUidAndFilename($path)
{
$view = new \OC\Files\View($this->userFilesDir);
$fileOwnerUid = $view->getOwner($path);
// handle public access
if ($this->isPublic) {
$filename = $path;
$fileOwnerUid = $GLOBALS['fileOwner'];
return array($fileOwnerUid, $filename);
} else {
// Check that UID is valid
if (!\OCP\User::userExists($fileOwnerUid)) {
throw new \Exception('Could not find owner (UID = "' . var_export($fileOwnerUid, 1) . '") of file "' . $path . '"');
}
// NOTE: Bah, this dependency should be elsewhere
\OC\Files\Filesystem::initMountPoints($fileOwnerUid);
// If the file owner is the currently logged in user
if ($fileOwnerUid === $this->userId) {
// Assume the path supplied is correct
$filename = $path;
} else {
$info = $view->getFileInfo($path);
$ownerView = new \OC\Files\View('/' . $fileOwnerUid . '/files');
// Fetch real file path from DB
$filename = $ownerView->getPath($info['fileid']);
// TODO: Check that this returns a path without including the user data dir
}
return array($fileOwnerUid, \OC_Filesystem::normalizePath($filename));
}
}