本文整理汇总了PHP中OC\Files\View::getFileInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP View::getFileInfo方法的具体用法?PHP View::getFileInfo怎么用?PHP View::getFileInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\View
的用法示例。
在下文中一共展示了View::getFileInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
private function create($imagePath, $square)
{
$galleryDir = \OC_User::getHome($this->user) . '/gallery/' . $this->user . '/';
$dir = dirname($imagePath);
$fileInfo = $this->view->getFileInfo($imagePath);
if (!$fileInfo) {
return false;
}
if (!is_dir($galleryDir . $dir)) {
mkdir($galleryDir . $dir, 0755, true);
}
$this->image = new \OCP\Image();
// check if file is encrypted
if ($fileInfo['encrypted'] === true) {
$fileName = $this->view->toTmpFile($imagePath);
} else {
$fileName = $this->view->getLocalFile($imagePath);
}
$this->image->loadFromFile($fileName);
if ($this->image->valid()) {
$this->image->fixOrientation();
if ($square) {
$this->image->centerCrop(200);
} else {
$this->image->fitIn($this->image->width(), 200);
if ($this->image->width() > 600) {
// max aspect ratio of 3
$this->image->crop(($this->image->width() - 600) / 2, 0, 600, 200);
}
}
$this->image->save($this->path);
}
}
示例2: getFileInfo
/**
* Returns the matching file info
*
* @return \OCP\Files\FileInfo
*/
public function getFileInfo()
{
if (!$this->fileInfo) {
$this->fileInfo = $this->view->getFileInfo($this->path);
}
return $this->fileInfo;
}
示例3: rename
/**
* rename a file
*
* @param string $dir
* @param string $oldname
* @param string $newname
* @return array
*/
public function rename($dir, $oldname, $newname)
{
$result = array('success' => false, 'data' => NULL);
$normalizedOldPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $oldname);
$normalizedNewPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname);
// rename to non-existing folder is denied
if (!$this->view->file_exists($normalizedOldPath)) {
$result['data'] = array('message' => $this->l10n->t('%s could not be renamed as it has been deleted', array($oldname)), 'code' => 'sourcenotfound', 'oldname' => $oldname, 'newname' => $newname);
} else {
if (!$this->view->file_exists($dir)) {
$result['data'] = array('message' => (string) $this->l10n->t('The target folder has been moved or deleted.', array($dir)), 'code' => 'targetnotfound');
// rename to existing file is denied
} else {
if ($this->view->file_exists($normalizedNewPath)) {
$result['data'] = array('message' => $this->l10n->t("The name %s is already used in the folder %s. Please choose a different name.", array($newname, $dir)));
} else {
if ($newname !== '.' and $this->view->rename($normalizedOldPath, $normalizedNewPath)) {
// successful rename
$meta = $this->view->getFileInfo($normalizedNewPath);
$meta = \OCA\Files\Helper::populateTags(array($meta));
$fileInfo = \OCA\Files\Helper::formatFileInfo(current($meta));
$fileInfo['path'] = dirname($normalizedNewPath);
$result['success'] = true;
$result['data'] = $fileInfo;
} else {
// rename failed
$result['data'] = array('message' => $this->l10n->t('%s could not be renamed', array($oldname)));
}
}
}
}
return $result;
}
示例4: testSizePropagationWhenRecipientChangesFile
public function testSizePropagationWhenRecipientChangesFile()
{
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
$recipientView = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$ownerView = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
$ownerView->mkdir('/sharedfolder/subfolder');
$ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar');
$sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false);
$this->assertInstanceOf('\\OC\\Files\\FileInfo', $sharedFolderInfo);
\OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31);
$ownerRootInfo = $ownerView->getFileInfo('', false);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
$this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt'));
$recipientRootInfo = $recipientView->getFileInfo('', false);
// when file changed as recipient
$recipientView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar');
// size of recipient's root stays the same
$newRecipientRootInfo = $recipientView->getFileInfo('', false);
$this->assertEquals($recipientRootInfo->getSize(), $newRecipientRootInfo->getSize());
// size of owner's root increases
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$newOwnerRootInfo = $ownerView->getFileInfo('', false);
$this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize());
}
示例5: rename
/**
* rename a file
*
* @param string $dir
* @param string $oldname
* @param string $newname
* @return array
*/
public function rename($dir, $oldname, $newname)
{
$result = array('success' => false, 'data' => NULL);
// rename to "/Shared" is denied
if ($dir === '/' and $newname === 'Shared') {
$result['data'] = array('message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved."));
// rename to existing file is denied
} else {
if ($this->view->file_exists($dir . '/' . $newname)) {
$result['data'] = array('message' => $this->l10n->t("The name %s is already used in the folder %s. Please choose a different name.", array($newname, $dir)));
} else {
if ($newname !== '.' and !($dir === '/' and $oldname === 'Shared') and $this->view->rename($dir . '/' . $oldname, $dir . '/' . $newname)) {
// successful rename
$meta = $this->view->getFileInfo($dir . '/' . $newname);
if ($meta['mimetype'] === 'httpd/unix-directory') {
$meta['type'] = 'dir';
} else {
$meta['type'] = 'file';
}
$fileinfo = array('id' => $meta['fileid'], 'mime' => $meta['mimetype'], 'size' => $meta['size'], 'etag' => $meta['etag'], 'directory' => $dir, 'name' => $newname, 'isPreviewAvailable' => \OC::$server->getPreviewManager()->isMimeSupported($meta['mimetype']), 'icon' => \OCA\Files\Helper::determineIcon($meta));
$result['success'] = true;
$result['data'] = $fileinfo;
} else {
// rename failed
$result['data'] = array('message' => $this->l10n->t('%s could not be renamed', array($oldname)));
}
}
}
return $result;
}
示例6: assertEtagsNotChanged
/**
* @param string[] $users
* @param string $subPath
*/
protected function assertEtagsNotChanged($users, $subPath = '')
{
$oldUser = \OC::$server->getUserSession()->getUser();
foreach ($users as $user) {
$this->loginAsUser($user);
$id = $this->fileIds[$user][$subPath];
$path = $this->rootView->getPath($id);
$etag = $this->rootView->getFileInfo($path)->getEtag();
$this->assertEquals($this->fileEtags[$id], $etag, 'Failed asserting that the etag for "' . $subPath . '" of user ' . $user . ' has not changed');
$this->fileEtags[$id] = $etag;
}
$this->loginAsUser($oldUser->getUID());
}
示例7: getNodeForPath
/**
* Returns the INode object for the requested path
*
* @param string $path
* @throws \Sabre\DAV\Exception\ServiceUnavailable
* @throws \Sabre\DAV\Exception\NotFound
* @return \Sabre\DAV\INode
*/
public function getNodeForPath($path)
{
if (!$this->fileView) {
throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
}
$path = trim($path, '/');
if (isset($this->cache[$path])) {
return $this->cache[$path];
}
// Is it the root node?
if (!strlen($path)) {
return $this->rootNode;
}
if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
// read from storage
$absPath = $this->fileView->getAbsolutePath($path);
$mount = $this->fileView->getMount($path);
$storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($absPath);
if ($storage) {
/**
* @var \OC\Files\Storage\Storage $storage
*/
$scanner = $storage->getScanner($internalPath);
// get data directly
$data = $scanner->getData($internalPath);
$info = new FileInfo($absPath, $storage, $internalPath, $data, $mount);
} else {
$info = null;
}
} else {
// read from cache
try {
$info = $this->fileView->getFileInfo($path);
} catch (StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable('Storage not available');
} catch (StorageInvalidException $e) {
throw new \Sabre\DAV\Exception\NotFound('Storage ' . $path . ' is invalid');
}
}
if (!$info) {
throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located');
}
if ($info->getType() === 'dir') {
$node = new \OC_Connector_Sabre_Directory($this->fileView, $info);
} else {
$node = new \OC_Connector_Sabre_File($this->fileView, $info);
}
$this->cache[$path] = $node;
return $node;
}
示例8: writeHook
public function writeHook($params)
{
$path = $params['path'];
$fullPath = $this->baseView->getAbsolutePath($path);
$mount = $this->baseView->getMount($path);
if ($mount instanceof SharedMount) {
$this->propagateForOwner($mount->getShare(), $mount->getInternalPath($fullPath), $mount->getOwnerPropagator());
}
$info = $this->baseView->getFileInfo($path);
if ($info) {
// trigger propagation if the subject of the write hook is shared.
// if a parent folder of $path is shared the propagation will be triggered from the change propagator hooks
$this->recipientPropagator->propagateById($info->getId());
}
}
示例9: getFileInfo
/**
* Returns the matching file info
*
* @return FileInfo
* @throws InvalidPathException
* @throws NotFoundException
*/
public function getFileInfo()
{
if (!Filesystem::isValidPath($this->path)) {
throw new InvalidPathException();
}
if (!$this->fileInfo) {
$fileInfo = $this->view->getFileInfo($this->path);
if ($fileInfo instanceof FileInfo) {
$this->fileInfo = $fileInfo;
} else {
throw new NotFoundException();
}
}
return $this->fileInfo;
}
示例10: getMaximumStorageUsage
/**
* @param string $userName
* @return integer
*/
public function getMaximumStorageUsage($userName)
{
$view = new FilesView('/' . $userName . '/files');
$freeSpace = (int) $view->free_space();
$usedSpace = $view->getFileInfo('/')->getSize();
return $freeSpace + $usedSpace;
}
示例11: testDeleteSharedFile
function testDeleteSharedFile()
{
// generate filename
$filename = 'tmp-' . $this->getUniqueID() . '.txt';
// save file with content
$cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename, $this->dataShort);
// test that data was successfully written
$this->assertTrue(is_int($cryptedFile));
// get the file info from previous created file
$fileInfo = $this->view->getFileInfo('/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename);
// check if we have a valid file info
$this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
// share the file
$this->assertTrue(\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_TRASHBIN_USER2, OCP\PERMISSION_ALL));
self::loginHelper(self::TEST_ENCRYPTION_TRASHBIN_USER2);
$this->assertTrue(\OC\Files\Filesystem::file_exists($filename));
\OCA\Files_Trashbin\Trashbin::move2trash($filename);
$query = \OC_DB::prepare('SELECT `timestamp` FROM `*PREFIX*files_trash`' . ' WHERE `id`=?');
$result = $query->execute(array($filename))->fetchRow();
$this->assertNotEmpty($result);
$timestamp = $result['timestamp'];
// check if key for both users exists
$this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename . '.key.d' . $timestamp));
// check if key for admin exists
$this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_TRASHBIN_USER2 . '/files_trashbin/keyfiles/' . $filename . '.key.d' . $timestamp));
// check if share key for both users exists
$this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.d' . $timestamp));
$this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_TRASHBIN_USER2 . '/files_trashbin/share-keys/' . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER2 . '.shareKey.d' . $timestamp));
}
示例12: testPropagateCrossStorage
public function testPropagateCrossStorage()
{
$storage = new Temporary();
$this->view->mkdir('/foo');
Filesystem::mount($storage, [], $this->view->getAbsolutePath('/foo/submount'));
$this->view->mkdir('/foo/submount/bar');
$this->view->file_put_contents('/foo/submount/bar/sad.txt', 'qwerty');
$oldInfo1 = $this->view->getFileInfo('/');
$oldInfo2 = $this->view->getFileInfo('/foo');
$oldInfo3 = $this->view->getFileInfo('/foo/submount');
$oldInfo4 = $this->view->getFileInfo('/foo/submount/bar');
$time = time() + 50;
$this->propagator->addChange('/foo/submount/bar/sad.txt');
$this->propagator->propagateChanges($time);
$newInfo1 = $this->view->getFileInfo('/');
$newInfo2 = $this->view->getFileInfo('/foo');
$newInfo3 = $this->view->getFileInfo('/foo/submount');
$newInfo4 = $this->view->getFileInfo('/foo/submount/bar');
$this->assertEquals($newInfo1->getMTime(), $time);
$this->assertEquals($newInfo2->getMTime(), $time);
$this->assertEquals($newInfo3->getMTime(), $time);
$this->assertEquals($newInfo4->getMTime(), $time);
$this->assertNotSame($oldInfo1->getEtag(), $newInfo1->getEtag());
$this->assertNotSame($oldInfo2->getEtag(), $newInfo2->getEtag());
$this->assertNotSame($oldInfo3->getEtag(), $newInfo3->getEtag());
$this->assertNotSame($oldInfo4->getEtag(), $newInfo3->getEtag());
}
示例13: doTestRestore
private function doTestRestore()
{
$filePath = self::TEST_VERSIONS_USER . '/files/sub/test.txt';
$this->rootView->file_put_contents($filePath, 'test file');
$t0 = $this->rootView->filemtime($filePath);
// not exactly the same timestamp as the file
$t1 = time() - 60;
// second version is two weeks older
$t2 = $t1 - 60 * 60 * 24 * 14;
// create some versions
$v1 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t1;
$v2 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t2;
$this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/sub');
$this->rootView->file_put_contents($v1, 'version1');
$this->rootView->file_put_contents($v2, 'version2');
$oldVersions = \OCA\Files_Versions\Storage::getVersions(self::TEST_VERSIONS_USER, '/sub/test.txt');
$this->assertCount(2, $oldVersions);
$this->assertEquals('test file', $this->rootView->file_get_contents($filePath));
$info1 = $this->rootView->getFileInfo($filePath);
\OCA\Files_Versions\Storage::rollback('sub/test.txt', $t2);
$this->assertEquals('version2', $this->rootView->file_get_contents($filePath));
$info2 = $this->rootView->getFileInfo($filePath);
$this->assertNotEquals($info2['etag'], $info1['etag'], 'Etag must change after rolling back version');
$this->assertEquals($info2['fileid'], $info1['fileid'], 'File id must not change after rolling back version');
$this->assertEquals($info2['mtime'], $t2, 'Restored file has mtime from version');
$newVersions = \OCA\Files_Versions\Storage::getVersions(self::TEST_VERSIONS_USER, '/sub/test.txt');
$this->assertTrue($this->rootView->file_exists(self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t0), 'A version file was created for the file before restoration');
$this->assertTrue($this->rootView->file_exists($v1), 'Untouched version file is still there');
$this->assertFalse($this->rootView->file_exists($v2), 'Restored version file gone from files_version folder');
$this->assertCount(2, $newVersions, 'Additional version created');
$this->assertTrue(isset($newVersions[$t0 . '#' . 'test.txt']), 'A version was created for the file before restoration');
$this->assertTrue(isset($newVersions[$t1 . '#' . 'test.txt']), 'Untouched version is still there');
$this->assertFalse(isset($newVersions[$t2 . '#' . 'test.txt']), 'Restored version is not in the list any more');
}
示例14: getPreview
/**
* @param string $owner
* @param int $fileId
* @param string $filePath
* @return array
*/
protected function getPreview($owner, $fileId, $filePath)
{
$info = $this->infoCache->getInfoById($owner, $fileId, $filePath);
if (!$info['exists'] || $info['view'] !== '') {
return $this->getPreviewFromPath($filePath, $info);
}
$preview = ['link' => $this->getPreviewLink($info['path'], $info['is_dir'], $info['view']), 'source' => '', 'isMimeTypeIcon' => true];
// show a preview image if the file still exists
if ($info['is_dir']) {
$preview['source'] = $this->getPreviewPathFromMimeType('dir');
} else {
$this->view->chroot('/' . $owner . '/files');
$fileInfo = $this->view->getFileInfo($info['path']);
if (!$fileInfo instanceof FileInfo) {
$pathPreview = $this->getPreviewFromPath($filePath, $info);
$preview['source'] = $pathPreview['source'];
} else {
if ($this->preview->isAvailable($fileInfo)) {
$preview['isMimeTypeIcon'] = false;
$preview['source'] = $this->urlGenerator->linkToRoute('core_ajax_preview', ['file' => $info['path'], 'c' => $this->view->getETag($info['path']), 'x' => 150, 'y' => 150]);
} else {
$preview['source'] = $this->getPreviewPathFromMimeType($fileInfo->getMimetype());
}
}
}
return $preview;
}
示例15: stream_close
/**
* @return bool
*/
public function stream_close()
{
$this->flush();
// if there is no valid private key return false
if ($this->privateKey === false) {
// cleanup
if ($this->meta['mode'] !== 'r' && $this->meta['mode'] !== 'rb' && !$this->isLocalTmpFile) {
// Disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
if ($this->rootView->file_exists($this->rawPath) && $this->size === 0) {
$this->rootView->unlink($this->rawPath);
}
// Re-enable proxy - our work is done
\OC_FileProxy::$enabled = $proxyStatus;
}
// if private key is not valid redirect user to a error page
\OCA\Encryption\Helper::redirectToErrorPage($this->session);
}
if ($this->meta['mode'] !== 'r' && $this->meta['mode'] !== 'rb' && $this->isLocalTmpFile === false && $this->size > 0 && $this->unencryptedSize > 0) {
// only write keyfiles if it was a new file
if ($this->newFile === true) {
// Disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
// Fetch user's public key
$this->publicKey = Keymanager::getPublicKey($this->rootView, $this->keyId);
// Check if OC sharing api is enabled
$sharingEnabled = \OCP\Share::isEnabled();
$util = new Util($this->rootView, $this->userId);
// Get all users sharing the file includes current user
$uniqueUserIds = $util->getSharingUsersArray($sharingEnabled, $this->relPath);
$checkedUserIds = $util->filterShareReadyUsers($uniqueUserIds);
// Fetch public keys for all sharing users
$publicKeys = Keymanager::getPublicKeys($this->rootView, $checkedUserIds['ready']);
// Encrypt enc key for all sharing users
$this->encKeyfiles = Crypt::multiKeyEncrypt($this->plainKey, $publicKeys);
// Save the new encrypted file key
Keymanager::setFileKey($this->rootView, $util, $this->relPath, $this->encKeyfiles['data']);
// Save the sharekeys
Keymanager::setShareKeys($this->rootView, $util, $this->relPath, $this->encKeyfiles['keys']);
// Re-enable proxy - our work is done
\OC_FileProxy::$enabled = $proxyStatus;
}
// we need to update the file info for the real file, not for the
// part file.
$path = Helper::stripPartialFileExtension($this->rawPath);
// get file info
$fileInfo = $this->rootView->getFileInfo($path);
if (is_array($fileInfo)) {
// set encryption data
$fileInfo['encrypted'] = true;
$fileInfo['size'] = $this->size;
$fileInfo['unencrypted_size'] = $this->unencryptedSize;
// set fileinfo
$this->rootView->putFileInfo($path, $fileInfo);
}
}
return fclose($this->handle);
}