View

class OC\Files\View
Class to provide access to ownCloud filesystem via a “view”, and methods for
working with files within that view (e.g. read, write, delete, etc.). Each
view is restricted to a set of directories via a virtual root. The default view
uses the currently logged in user’s data directory as root (parts of
OC_Filesystem are merely a wrapper for OC\Files\View).
Apps that need to access files outside of the user data folders (to modify files
belonging to a user other than the one currently logged in, for example) should
use this class directly rather than using OC_Filesystem, or making use of PHP’s
built-in file manipulation functions. This will ensure all hooks and proxies
are triggered correctly.

Filesystem functions are not called directly; they are passed to the correct
\OC\Files\Storage\Storage object
Source:lib/private/Files/View.php#87

Properties

protected static property OC\Files\View::$lockingProvider
Source:lib/private/Files/View.php#94
Type:\OCP\Lock\ILockingProvider

Methods

public OC\Files\View::__construct($root="")
Source:

lib/private/Files/View.php#110

Parameters:
  • $root (string)
Throws:

\Exception If $root contains an invalid path

public OC\Files\View::getAbsolutePath($path=/)
Source:lib/private/Files/View.php#125
public OC\Files\View::chroot($fakeRoot)
change the root to a fake root
Source:

lib/private/Files/View.php#145

Parameters:
  • $fakeRoot (string)
Returns:

bool | null

public OC\Files\View::getRoot()
get the fake root
Source:lib/private/Files/View.php#159
Returns:string
public OC\Files\View::getRelativePath($path)
get path relative to the root of the view
Source:

lib/private/Files/View.php#169

Parameters:
  • $path (string)
Returns:

string

public OC\Files\View::getMountPoint($path)
get the mountpoint of the storage object for a path
( note: because a storage is not always mounted inside the fakeroot, the
returned mountpoint is relative to the absolute root of the filesystem
and does not take the chroot into account )
Source:

lib/private/Files/View.php#203

Parameters:
  • $path (string)
Returns:

string

public OC\Files\View::getMount($path)
get the mountpoint of the storage object for a path
( note: because a storage is not always mounted inside the fakeroot, the
returned mountpoint is relative to the absolute root of the filesystem
and does not take the chroot into account )
Source:

lib/private/Files/View.php#216

Parameters:
  • $path (string)
Returns:

\OCP\Files\Mount\IMountPoint

public OC\Files\View::resolvePath($path)
resolve a path to a storage and internal path
Source:

lib/private/Files/View.php#226

Parameters:
  • $path (string)
Returns:

array an array consisting of the storage and the internal path

public OC\Files\View::getLocalFile($path)
return the path to a local version of the file
we need this because we can’t know if a file is stored local or not from
outside the filestorage and for some purposes a local file is needed
Source:

lib/private/Files/View.php#240

Parameters:
  • $path (string)
Returns:

string

public OC\Files\View::getLocalFolder($path)
Source:

lib/private/Files/View.php#255

Parameters:
  • $path (string)
Returns:

string

public OC\Files\View::mkdir($path)
the following functions operate with arguments and return values identical
to those of their PHP built-in equivalents. Mostly they are merely wrappers
for \OC\Files\Storage\Storage via basicOperation().
Source:lib/private/Files/View.php#271
protected OC\Files\View::removeMount($mount, $path)
remove mount point
Source:

lib/private/Files/View.php#282

Parameters:
Returns:

bool

public OC\Files\View::disableCacheUpdate()
Source:lib/private/Files/View.php#311
public OC\Files\View::enableCacheUpdate()
Source:lib/private/Files/View.php#315
protected OC\Files\View::writeUpdate($storage, $internalPath, $time=null)
Source:lib/private/Files/View.php#319
protected OC\Files\View::removeUpdate($storage, $internalPath)
Source:lib/private/Files/View.php#328
protected OC\Files\View::renameUpdate($sourceStorage, $targetStorage, $sourceInternalPath, $targetInternalPath)
Source:lib/private/Files/View.php#334
public OC\Files\View::rmdir($path)
Source:

lib/private/Files/View.php#344

Parameters:
  • $path (string)
Returns:

bool | mixed

public OC\Files\View::opendir($path)
Source:

lib/private/Files/View.php#368

Parameters:
  • $path (string)
Returns:

resource

public OC\Files\View::is_dir($path)
Source:

lib/private/Files/View.php#376

Parameters:
  • $path (string)
Returns:

bool | mixed

public OC\Files\View::is_file($path)
Source:

lib/private/Files/View.php#387

Parameters:
  • $path (string)
Returns:

bool | mixed

public OC\Files\View::stat($path)
Source:

lib/private/Files/View.php#398

Parameters:
  • $path (string)
Returns:

mixed

public OC\Files\View::filetype($path)
Source:

lib/private/Files/View.php#406

Parameters:
  • $path (string)
Returns:

mixed

public OC\Files\View::filesize($path)
Source:

lib/private/Files/View.php#414

Parameters:
  • $path (string)
Returns:

mixed

public OC\Files\View::readfile($path)
Source:

lib/private/Files/View.php#423

Parameters:
  • $path (string)
Returns:

bool | mixed

Throws:

\OCP\Files\InvalidPathException

public OC\Files\View::readfilePart($path, $from, $to)
Source:

lib/private/Files/View.php#447

Parameters:
  • $path (string)
  • $from (int)
  • $to (int)
Returns:

bool | mixed

Throws:

\OCP\Files\InvalidPathException

Throws:

\OCP\Files\UnseekableException

Throws:

\OCP\Files\InvalidPathException

Throws:

\OCP\Files\UnseekableException

public OC\Files\View::isCreatable($path)
Source:

lib/private/Files/View.php#495

Parameters:
  • $path (string)
Returns:

mixed

public OC\Files\View::isReadable($path)
Source:

lib/private/Files/View.php#503

Parameters:
  • $path (string)
Returns:

mixed

public OC\Files\View::isUpdatable($path)
Source:

lib/private/Files/View.php#511

Parameters:
  • $path (string)
Returns:

mixed

public OC\Files\View::isDeletable($path)
Source:

lib/private/Files/View.php#519

Parameters:
  • $path (string)
Returns:

bool | mixed

public OC\Files\View::isSharable($path)
Source:

lib/private/Files/View.php#532

Parameters:
  • $path (string)
Returns:

mixed

public OC\Files\View::file_exists($path)
Source:

lib/private/Files/View.php#540

Parameters:
  • $path (string)
Returns:

bool | mixed

public OC\Files\View::filemtime($path)
Source:

lib/private/Files/View.php#551

Parameters:
  • $path (string)
Returns:

mixed

public OC\Files\View::touch($path, $mtime=null)
Source:

lib/private/Files/View.php#560

Parameters:
  • $path (string)
  • $mtime (int | string)
Returns:

bool

public OC\Files\View::file_get_contents($path)
Source:

lib/private/Files/View.php#597

Parameters:
  • $path (string)
Returns:

mixed

Throws:

\OCP\Lock\LockedException

protected OC\Files\View::emit_file_hooks_pre($exists, $path, &$run)
Source:

lib/private/Files/View.php#606

Parameters:
  • $exists (bool)
  • $path (string)
  • $run (bool)
protected OC\Files\View::emit_file_hooks_post($exists, $path)
Source:

lib/private/Files/View.php#628

Parameters:
  • $exists (bool)
  • $path (string)
public OC\Files\View::file_put_contents($path, $data)
Source:

lib/private/Files/View.php#649

Parameters:
  • $path (string)
  • $data (string | resource)
Returns:

bool | mixed

Throws:

\OCP\Lock\LockedException

Source:

lib/private/Files/View.php#711

Parameters:
  • $path (string)
Returns:

bool | mixed

public OC\Files\View::deleteAll($directory)
Source:

lib/private/Files/View.php#741

Parameters:
  • $directory (string)
Returns:

bool | mixed

public OC\Files\View::rename($path1, $path2)
Rename/move a file or folder from the source path to target path.
Source:

lib/private/Files/View.php#754

Parameters:
  • $path1 (string) source path
  • $path2 (string) target path
Returns:

bool | mixed

Throws:

\OCP\Lock\LockedException

public OC\Files\View::copy($path1, $path2, $preserveMtime=false)
Copy a file/folder from the source path to target path
Source:

lib/private/Files/View.php#883

Parameters:
  • $path1 (string) source path
  • $path2 (string) target path
  • $preserveMtime (bool) whether to preserve mtime on the copy
Returns:

bool | mixed

public OC\Files\View::fopen($path, $mode)
Source:

lib/private/Files/View.php#975

Parameters:
  • $path (string)
  • $mode (string) ‘r’ or ‘w’
Returns:

resource

Throws:

\OCP\Lock\LockedException

public OC\Files\View::toTmpFile($path)
Source:

lib/private/Files/View.php#1010

Parameters:
  • $path (string)
Returns:

bool | string

Throws:

\OCP\Files\InvalidPathException

public OC\Files\View::fromTmpFile($tmpFile, $path)
Source:

lib/private/Files/View.php#1033

Parameters:
  • $tmpFile (string)
  • $path (string)
Returns:

bool | mixed

Throws:

\OCP\Files\InvalidPathException

public OC\Files\View::getMimeType($path)
Source:

lib/private/Files/View.php#1073

Parameters:
  • $path (string)
Returns:

mixed

Throws:

\OCP\Files\InvalidPathException

public OC\Files\View::hash($type, $path, $raw=false)
Source:

lib/private/Files/View.php#1084

Parameters:
  • $type (string)
  • $path (string)
  • $raw (bool)
Returns:

bool | null | string

public OC\Files\View::free_space($path=/)
Source:

lib/private/Files/View.php#1112

Parameters:
  • $path (string)
Returns:

mixed

Throws:

\OCP\Files\InvalidPathException

public OC\Files\View::hasUpdated($path, $time)
check if a file or folder has been updated since $time
Source:

lib/private/Files/View.php#1305

Parameters:
  • $path (string)
  • $time (int)
Returns:

bool

public OC\Files\View::getFileInfo($path, $includeMountPoints=true)
get the filesystem info
Source:

lib/private/Files/View.php#1371

Parameters:
  • $path (string)
  • $includeMountPoints (bool | string) true to add mountpoint sizes,

‘ext’ to add only ext storage mount point sizes. Defaults to true. defaults to true

Returns:

\OC\Files\FileInfo | bool False if file does not exist

public OC\Files\View::getDirectoryContent($directory, $mimetype_filter="")
get the content of a directory
Source:

lib/private/Files/View.php#1434

Parameters:
  • $directory (string) path under datadirectory
  • $mimetype_filter (string) limit returned content to this mimetype or mimepart
Returns:

\OC\Files\FileInfo[]

public OC\Files\View::putFileInfo($path, $data)
change file metadata
Source:

lib/private/Files/View.php#1568

Parameters:
Returns:

int returns the fileid of the updated file

public OC\Files\View::search($query)
search for files with the name matching $query
Source:

lib/private/Files/View.php#1599

Parameters:
  • $query (string)
Returns:

\OC\Files\FileInfo[]

public OC\Files\View::searchRaw($query)
search for files with the name matching $query
Source:

lib/private/Files/View.php#1609

Parameters:
  • $query (string)
Returns:

\OC\Files\FileInfo[]

public OC\Files\View::searchByMime($mimetype)
search for files by mimetype
Source:

lib/private/Files/View.php#1619

Parameters:
  • $mimetype (string)
Returns:

\OC\Files\FileInfo[]

public OC\Files\View::searchByTag($tag, $userId)
search for files by tag
Source:

lib/private/Files/View.php#1630

Parameters:
  • $tag (string | int) name or tag id
  • $userId (string) owner of the tags
Returns:

\OC\Files\FileInfo[]

public OC\Files\View::getOwner($path)
Get the owner for a file or folder
Source:

lib/private/Files/View.php#1692

Parameters:
  • $path (string)
Returns:

string the user id of the owner

Throws:

\OCP\Files\NotFoundException

public OC\Files\View::getETag($path)
get the ETag for a file or folder
Source:

lib/private/Files/View.php#1711

Parameters:
  • $path (string)
Returns:

string

public OC\Files\View::getPath($id, $storageId=null)
Get the path of a file by id, relative to the view
Note that the resulting path is not guarantied to be unique for the id, multiple paths can point to the same file
Source:

lib/private/Files/View.php#1734

Parameters:
  • $id (int)
  • $storageId (int | null)
Returns:

string

Throws:

\OCP\Files\NotFoundException

public OC\Files\View::verifyPath($path, $fileName)
Source:

lib/private/Files/View.php#1859

Parameters:
  • $path (string)
  • $fileName (string)
Throws:

\OCP\Files\InvalidPathException

public OC\Files\View::changeLock($path, $type, $lockMountPoint=false)
Change the lock type
Source:

lib/private/Files/View.php#1987

Parameters:
  • $path (string) the path of the file to lock, relative to the view
  • $type (int) OCPLockILockingProvider::LOCK_SHARED or OCPLockILockingProvider::LOCK_EXCLUSIVE
  • $lockMountPoint (bool) true to lock the mount point, false to lock the attached mount/storage
Returns:

bool False if the path is excluded from locking, true otherwise

Throws:

\OCP\Lock\LockedException if the path is already locked

public OC\Files\View::lockFile($path, $type, $lockMountPoint=false)
Lock a path and all its parents up to the root of the view
Source:

lib/private/Files/View.php#2069

Parameters:
  • $path (string) the path of the file to lock relative to the view
  • $type (int) OCPLockILockingProvider::LOCK_SHARED or OCPLockILockingProvider::LOCK_EXCLUSIVE
  • $lockMountPoint (bool) true to lock the mount point, false to lock the attached mount/storage
Returns:

bool False if the path is excluded from locking, true otherwise

Throws:

\OCP\Lock\LockedException

public OC\Files\View::unlockFile($path, $type, $lockMountPoint=false)
Unlock a path and all its parents up to the root of the view
Source:

lib/private/Files/View.php#2096

Parameters:
  • $path (string) the path of the file to lock relative to the view
  • $type (int) OCPLockILockingProvider::LOCK_SHARED or OCPLockILockingProvider::LOCK_EXCLUSIVE
  • $lockMountPoint (bool) true to lock the mount point, false to lock the attached mount/storage
Returns:

bool False if the path is excluded from locking, true otherwise

Throws:

\OCP\Lock\LockedException

protected OC\Files\View::shouldLockFile($path)
Only lock files in data/user/files/
Source:

lib/private/Files/View.php#2119

Parameters:
  • $path (string) Absolute path to the file/folder we try to (un)lock
Returns:

bool

public OC\Files\View::getPathRelativeToFiles($absolutePath)
Shortens the given absolute path to be relative to
“$user/files”.
Source:

lib/private/Files/View.php#2143

Parameters:
  • $absolutePath (string) absolute path which is under “files”
Returns:

string path relative to “files” with trimmed slashes or null if the path was NOT relative to files

Throws:

\InvalidArgumentException if the given path was not under “files”

Since:

8.1.0

public OC\Files\View::getUidAndFilename($filename)
Source:

lib/private/Files/View.php#2168

Parameters:
  • $filename (string)
Returns:

array

Throws:

\OC\User\NoUserException

Throws:

\OCP\Files\NotFoundException

Throws:

\OC\User\NoUserException

Throws:

\OCP\Files\NotFoundException