本文整理汇总了PHP中OC\Files\View::file_put_contents方法的典型用法代码示例。如果您正苦于以下问题:PHP View::file_put_contents方法的具体用法?PHP View::file_put_contents怎么用?PHP View::file_put_contents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\View
的用法示例。
在下文中一共展示了View::file_put_contents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSinglePropagate
public function testSinglePropagate() {
$this->view->mkdir('/foo');
$this->view->mkdir('/foo/bar');
$this->view->file_put_contents('/foo/bar/sad.txt', 'qwerty');
$oldInfo1 = $this->view->getFileInfo('/');
$oldInfo2 = $this->view->getFileInfo('/foo');
$oldInfo3 = $this->view->getFileInfo('/foo/bar');
$time = time() + 50;
$this->propagator->addChange('/foo/bar/sad.txt');
$this->propagator->propagateChanges($time);
$newInfo1 = $this->view->getFileInfo('/');
$newInfo2 = $this->view->getFileInfo('/foo');
$newInfo3 = $this->view->getFileInfo('/foo/bar');
$this->assertEquals($newInfo1->getMTime(), $time);
$this->assertEquals($newInfo2->getMTime(), $time);
$this->assertEquals($newInfo3->getMTime(), $time);
$this->assertNotSame($oldInfo1->getEtag(), $newInfo1->getEtag());
$this->assertNotSame($oldInfo2->getEtag(), $newInfo2->getEtag());
$this->assertNotSame($oldInfo3->getEtag(), $newInfo3->getEtag());
}
示例2: setUpShares
/**
* "user1" is the admin who shares a folder "sub1/sub2/folder" with "user2" and "user3"
* "user2" receives the folder and puts it in "sub1/sub2/folder"
* "user3" receives the folder and puts it in "sub1/sub2/folder"
* "user2" reshares the subdir "sub1/sub2/folder/inside" with "user4"
* "user4" puts the received "inside" folder into "sub1/sub2/inside" (this is to check if it propagates across multiple subfolders)
*/
private function setUpShares()
{
$this->fileIds[self::TEST_FILES_SHARING_API_USER1] = [];
$this->fileIds[self::TEST_FILES_SHARING_API_USER2] = [];
$this->fileIds[self::TEST_FILES_SHARING_API_USER3] = [];
$this->fileIds[self::TEST_FILES_SHARING_API_USER4] = [];
$this->rootView = new View('');
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
$view1->mkdir('/sub1/sub2/folder/inside');
$view1->mkdir('/directReshare');
$view1->mkdir('/sub1/sub2/folder/other');
$view1->mkdir('/sub1/sub2/folder/other');
$view1->file_put_contents('/foo.txt', 'foobar');
$view1->file_put_contents('/sub1/sub2/folder/file.txt', 'foobar');
$view1->file_put_contents('/sub1/sub2/folder/inside/file.txt', 'foobar');
$folderInfo = $view1->getFileInfo('/sub1/sub2/folder');
$fileInfo = $view1->getFileInfo('/foo.txt');
\OCP\Share::shareItem('file', $fileInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
\OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
\OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31);
$folderInfo = $view1->getFileInfo('/directReshare');
\OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
$this->fileIds[self::TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1'] = $view1->getFileInfo('sub1')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1/sub2'] = $view1->getFileInfo('sub1/sub2')->getId();
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
$view2->mkdir('/sub1/sub2');
$view2->rename('/folder', '/sub1/sub2/folder');
$insideInfo = $view2->getFileInfo('/sub1/sub2/folder/inside');
\OCP\Share::shareItem('folder', $insideInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31);
$folderInfo = $view2->getFileInfo('/directReshare');
\OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31);
$this->fileIds[self::TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1'] = $view2->getFileInfo('sub1')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1/sub2'] = $view2->getFileInfo('sub1/sub2')->getId();
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
$view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
$view3->mkdir('/sub1/sub2');
$view3->rename('/folder', '/sub1/sub2/folder');
$this->fileIds[self::TEST_FILES_SHARING_API_USER3][''] = $view3->getFileInfo('')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1'] = $view3->getFileInfo('sub1')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1/sub2'] = $view3->getFileInfo('sub1/sub2')->getId();
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
$view4 = new View('/' . self::TEST_FILES_SHARING_API_USER4 . '/files');
$view4->mkdir('/sub1/sub2');
$view4->rename('/inside', '/sub1/sub2/inside');
$this->fileIds[self::TEST_FILES_SHARING_API_USER4][''] = $view4->getFileInfo('')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub1'] = $view4->getFileInfo('sub1')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub1/sub2'] = $view4->getFileInfo('sub1/sub2')->getId();
foreach ($this->fileIds as $user => $ids) {
$this->loginAsUser($user);
foreach ($ids as $id) {
$path = $this->rootView->getPath($id);
$this->fileEtags[$id] = $this->rootView->getFileInfo($path)->getEtag();
}
}
}
示例3: testUpdatedFile
public function testUpdatedFile()
{
$this->view->file_put_contents('/foo.txt', 'bar');
$cached = $this->cache->get('foo.txt');
$this->assertEquals(3, $cached['size']);
$this->assertEquals('text/plain', $cached['mimetype']);
$this->storage->file_put_contents('foo.txt', 'qwerty');
$cached = $this->cache->get('foo.txt');
$this->assertEquals(3, $cached['size']);
$this->updater->update('/foo.txt');
$cached = $this->cache->get('foo.txt');
$this->assertEquals(6, $cached['size']);
}
示例4: 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');
}
示例5: 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());
}
示例6: testStreamDecryptLongFileContentWithoutHeader
/**
* @medium
* Test that data that is written by the crypto stream wrapper with AES 128
* @note Encrypted data is manually prepared and decrypted here to avoid dependency on success of stream_read
* @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual
* reassembly of its data
*/
public function testStreamDecryptLongFileContentWithoutHeader()
{
// Generate a a random filename
$filename = 'tmp-' . $this->getUniqueID() . '.test';
$this->config->setSystemValue('cipher', 'AES-128-CFB');
// Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong . $this->dataLong);
$this->config->deleteSystemValue('cipher');
// Test that data was successfully written
$this->assertTrue(is_int($cryptedFile));
// Disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
// Get file contents without using any wrapper to get it's actual contents on disk
$retreivedCryptedFile = $this->view->file_get_contents($this->userId . '/files/' . $filename);
// Check that the file was encrypted before being written to disk
$this->assertNotEquals($this->dataLong . $this->dataLong, $retreivedCryptedFile);
// remove the header to check if we can also decrypt old files without a header,
// this files should fall back to AES-128
$cryptedWithoutHeader = substr($retreivedCryptedFile, \OCA\Files_Encryption\Crypt::BLOCKSIZE);
$this->view->file_put_contents($this->userId . '/files/' . $filename, $cryptedWithoutHeader);
// Re-enable proxy - our work is done
\OC_FileProxy::$enabled = $proxyStatus;
$decrypted = file_get_contents('crypt:///' . $this->userId . '/files/' . $filename);
$this->assertEquals($this->dataLong . $this->dataLong, $decrypted);
// Teardown
$this->view->unlink($this->userId . '/files/' . $filename);
}
示例7: testStreamFromLocalFile
/**
* @medium
* test if stream wrapper can read files outside from the data folder
*/
function testStreamFromLocalFile()
{
$filename = '/' . $this->userId . '/files/' . 'tmp-' . $this->getUniqueID() . '.txt';
$tmpFilename = "/tmp/" . $this->getUniqueID() . ".txt";
// write an encrypted file
$cryptedFile = $this->view->file_put_contents($filename, $this->dataShort);
// Test that data was successfully written
$this->assertTrue(is_int($cryptedFile));
// create a copy outside of the data folder in /tmp
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
$encryptedContent = $this->view->file_get_contents($filename);
\OC_FileProxy::$enabled = $proxyStatus;
file_put_contents($tmpFilename, $encryptedContent);
\OCA\Files_Encryption\Helper::addTmpFileToMapper($tmpFilename, $filename);
// try to read the file from /tmp
$handle = fopen("crypt://" . $tmpFilename, "r");
$contentFromTmpFile = stream_get_contents($handle);
// check if it was successful
$this->assertEquals($this->dataShort, $contentFromTmpFile);
fclose($handle);
// clean up
unlink($tmpFilename);
$this->view->unlink($filename);
}
示例8: 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());
}
示例9: set
/**
* sets the users avatar
* @param \OCP\IImage|resource|string $data An image object, imagedata or path to set a new avatar
* @throws \Exception if the provided file is not a jpg or png image
* @throws \Exception if the provided image is not valid
* @throws \OC\NotSquareException if the image is not square
* @return void
*/
public function set($data)
{
if ($data instanceof \OCP\IImage) {
$img = $data;
$data = $img->data();
} else {
$img = new OC_Image($data);
}
$type = substr($img->mimeType(), -3);
if ($type === 'peg') {
$type = 'jpg';
}
if ($type !== 'jpg' && $type !== 'png') {
$l = \OC::$server->getL10N('lib');
throw new \Exception($l->t("Unknown filetype"));
}
if (!$img->valid()) {
$l = \OC::$server->getL10N('lib');
throw new \Exception($l->t("Invalid image"));
}
if (!($img->height() === $img->width())) {
throw new \OC\NotSquareException();
}
$this->view->unlink('avatar.jpg');
$this->view->unlink('avatar.png');
$this->view->file_put_contents('avatar.' . $type, $data);
}
示例10: setUp
protected function setUp()
{
$app = new Application();
$this->container = $app->getContainer();
$this->container['Config'] = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock();
$this->container['AppName'] = 'files_sharing';
$this->container['UserSession'] = $this->getMockBuilder('\\OC\\User\\Session')->disableOriginalConstructor()->getMock();
$this->container['URLGenerator'] = $this->getMockBuilder('\\OC\\URLGenerator')->disableOriginalConstructor()->getMock();
$this->urlGenerator = $this->container['URLGenerator'];
$this->shareController = $this->container['ShareController'];
// Store current user
$this->oldUser = \OC_User::getUser();
// Create a dummy user
$this->user = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(12, ISecureRandom::CHAR_LOWER);
\OC_User::createUser($this->user, $this->user);
\OC_Util::tearDownFS();
\OC_User::setUserId('');
Filesystem::tearDown();
\OC_User::setUserId($this->user);
\OC_Util::setupFS($this->user);
// Create a dummy shared file
$view = new View('/' . $this->user . '/files');
$view->file_put_contents('file1.txt', 'I am such an awesome shared file!');
$this->token = \OCP\Share::shareItem(Filesystem::getFileInfo('file1.txt')->getType(), Filesystem::getFileInfo('file1.txt')->getId(), \OCP\Share::SHARE_TYPE_LINK, 'IAmPasswordProtected!', 1);
}
示例11: testIsExcludedPath
/**
* @dataProvider isExcludedPathProvider
*/
function testIsExcludedPath($path, $expected)
{
$this->view->mkdir(dirname($path));
$this->view->file_put_contents($path, "test");
$result = \Test_Helper::invokePrivate(new \OCA\Files_Encryption\Proxy(), 'isExcludedPath', array($path));
$this->assertSame($expected, $result);
$this->view->deleteAll(dirname($path));
}
示例12: prepareSample
/**
* Stores the sample in the filesystem and stores it in the $samples array
*
* @param string $fileName
* @param int $sampleWidth
* @param int $sampleHeight
*/
private function prepareSample($fileName, $sampleWidth, $sampleHeight)
{
$imgData = file_get_contents(\OC::$SERVERROOT . '/tests/data/' . $fileName);
$imgPath = '/' . self::TEST_PREVIEW_USER1 . '/files/' . $fileName;
$this->rootView->file_put_contents($imgPath, $imgData);
$fileInfo = $this->rootView->getFileInfo($imgPath);
list($maxPreviewWidth, $maxPreviewHeight) = $this->setMaxPreview($sampleWidth, $sampleHeight);
$this->samples[] = ['sampleFileId' => $fileInfo['fileid'], 'sampleFileName' => $fileName, 'sampleWidth' => $sampleWidth, 'sampleHeight' => $sampleHeight, 'maxPreviewWidth' => $maxPreviewWidth, 'maxPreviewHeight' => $maxPreviewHeight];
}
示例13: testIsExcludedPath
/**
* @dataProvider isExcludedPathProvider
*/
function testIsExcludedPath($path, $expected)
{
$this->view->mkdir(dirname($path));
$this->view->file_put_contents($path, "test");
$testClass = new DummyProxy();
$result = $testClass->isExcludedPathTesting($path, $this->userId);
$this->assertSame($expected, $result);
$this->view->deleteAll(dirname($path));
}
示例14: createDummySystemWideKeys
protected function createDummySystemWideKeys()
{
$this->view->mkdir('files_encryption');
$this->view->mkdir('files_encryption/public_keys');
$this->view->file_put_contents('files_encryption/systemwide_1.privateKey', 'data');
$this->view->file_put_contents('files_encryption/systemwide_2.privateKey', 'data');
$this->view->file_put_contents('files_encryption/public_keys/systemwide_1.publicKey', 'data');
$this->view->file_put_contents('files_encryption/public_keys/systemwide_2.publicKey', 'data');
}
示例15: prepareTestFile
/**
* Adds the test file to the filesystem
*
* @param string $fileName name of the file to create
* @param string $fileContent path to file to use for test
*
* @return string
*/
protected function prepareTestFile($fileName, $fileContent)
{
$imgData = file_get_contents($fileContent);
$imgPath = '/' . $this->userId . '/files/' . $fileName;
$this->rootView->file_put_contents($imgPath, $imgData);
$scanner = $this->storage->getScanner();
$scanner->scan('');
return $imgPath;
}