本文整理汇总了PHP中OC\Files\Filesystem::file_put_contents方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::file_put_contents方法的具体用法?PHP Filesystem::file_put_contents怎么用?PHP Filesystem::file_put_contents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\Filesystem
的用法示例。
在下文中一共展示了Filesystem::file_put_contents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: put
/**
* Updates the data
*
* The data argument is a readable stream resource.
*
* After a succesful put operation, you may choose to return an ETag. The
* etag must always be surrounded by double-quotes. These quotes must
* appear in the actual string you're returning.
*
* Clients may use the ETag from a PUT request to later on make sure that
* when they update the file, the contents haven't changed in the mean
* time.
*
* If you don't plan to store the file byte-by-byte, and you return a
* different object on a subsequent GET you are strongly recommended to not
* return an ETag, and just return null.
*
* @param resource $data
* @throws Sabre_DAV_Exception_Forbidden
* @return string|null
*/
public function put($data)
{
if (!\OC\Files\Filesystem::isUpdatable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}
// mark file as partial while uploading (ignored by the scanner)
$partpath = $this->path . '.part';
\OC\Files\Filesystem::file_put_contents($partpath, $data);
//detect aborted upload
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
if (isset($_SERVER['CONTENT_LENGTH'])) {
$expected = $_SERVER['CONTENT_LENGTH'];
$actual = \OC\Files\Filesystem::filesize($partpath);
if ($actual != $expected) {
\OC\Files\Filesystem::unlink($partpath);
throw new Sabre_DAV_Exception_BadRequest('expected filesize ' . $expected . ' got ' . $actual);
}
}
}
// rename to correct path
\OC\Files\Filesystem::rename($partpath, $this->path);
//allow sync clients to send the mtime along in a header
$mtime = OC_Request::hasModificationTime();
if ($mtime !== false) {
if (\OC\Files\Filesystem::touch($this->path, $mtime)) {
header('X-OC-MTime: accepted');
}
}
return OC_Connector_Sabre_Node::getETagPropertyForPath($this->path);
}
示例2: setUp
public function setUp()
{
parent::setUp();
\OC_User::clearBackends();
\OC_User::useBackend(new \OC_User_Dummy());
\OC\Files\Filesystem::clearMounts();
//login
\OC_User::createUser('test', 'test');
\OC::$server->getSession()->set('user_id', 'test');
$this->storage = new \OC\Files\Storage\Temporary(array());
\OC\Files\Filesystem::init('test', '');
\OC\Files\Filesystem::clearMounts();
\OC\Files\Filesystem::mount($this->storage, array(), '/');
\OC\Files\Filesystem::file_put_contents('file1', self::CONTENT);
$this->config->method('getAvChunkSize')->willReturn('1024');
}
示例3: createFile
/**
* Creates a new file in the directory
*
* Data will either be supplied as a stream resource, or in certain cases
* as a string. Keep in mind that you may have to support either.
*
* After succesful creation of the file, you may choose to return the ETag
* of the new file here.
*
* The returned ETag must be surrounded by double-quotes (The quotes should
* be part of the actual string).
*
* If you cannot accurately determine the ETag, you should not return it.
* If you don't store the file exactly as-is (you're transforming it
* somehow) you should also not return an ETag.
*
* This means that if a subsequent GET to this new file does not exactly
* return the same contents of what was submitted here, you are strongly
* recommended to omit the ETag.
*
* @param string $name Name of the file
* @param resource|string $data Initial payload
* @throws Sabre_DAV_Exception_Forbidden
* @return null|string
*/
public function createFile($name, $data = null)
{
if (!\OC\Files\Filesystem::isCreatable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}
if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
$info = OC_FileChunking::decodeName($name);
if (empty($info)) {
throw new Sabre_DAV_Exception_NotImplemented();
}
$chunk_handler = new OC_FileChunking($info);
$chunk_handler->store($info['index'], $data);
if ($chunk_handler->isComplete()) {
$newPath = $this->path . '/' . $info['name'];
$chunk_handler->file_assemble($newPath);
return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
}
} else {
$newPath = $this->path . '/' . $name;
// mark file as partial while uploading (ignored by the scanner)
$partpath = $newPath . '.part';
\OC\Files\Filesystem::file_put_contents($partpath, $data);
//detect aborted upload
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
if (isset($_SERVER['CONTENT_LENGTH'])) {
$expected = $_SERVER['CONTENT_LENGTH'];
$actual = \OC\Files\Filesystem::filesize($partpath);
if ($actual != $expected) {
\OC\Files\Filesystem::unlink($partpath);
throw new Sabre_DAV_Exception_BadRequest('expected filesize ' . $expected . ' got ' . $actual);
}
}
}
// rename to correct path
\OC\Files\Filesystem::rename($partpath, $newPath);
// allow sync clients to send the mtime along in a header
$mtime = OC_Request::hasModificationTime();
if ($mtime !== false) {
if (\OC\Files\Filesystem::touch($newPath, $mtime)) {
header('X-OC-MTime: accepted');
}
}
return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
}
return null;
}
示例4: setUp
public function setUp()
{
parent::setUp();
$this->userBackend = new \Test\Util\User\Dummy();
\OC::$server->getUserManager()->registerBackend($this->userBackend);
$this->ownerUid = $this->getUniqueID('owner_');
$this->recipientUid = $this->getUniqueID('recipient_');
$this->userBackend->createUser($this->ownerUid, '');
$this->userBackend->createUser($this->recipientUid, '');
$this->loginAsUser($this->ownerUid);
Filesystem::mkdir('/foo');
Filesystem::file_put_contents('/foo/bar.txt', 'asd');
$fileId = Filesystem::getFileInfo('/foo/bar.txt')->getId();
\OCP\Share::shareItem('file', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->recipientUid, 31);
$this->loginAsUser($this->recipientUid);
$this->assertTrue(Filesystem::file_exists('bar.txt'));
}
示例5: testNewUser
public function testNewUser()
{
$user1 = $this->getUniqueID('user_');
$this->userBackend->createUser($user1, '');
$this->loginAsUser($user1);
Filesystem::mkdir('/folder');
Filesystem::mkdir('/folder/subfolder');
Filesystem::file_put_contents('/foo.txt', 'asd');
Filesystem::file_put_contents('/folder/bar.txt', 'fgh');
Filesystem::file_put_contents('/folder/subfolder/qwerty.txt', 'jkl');
$files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt');
$originalEtags = $this->getEtags($files);
$scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
$scanner->backgroundScan('/');
$newEtags = $this->getEtags($files);
// loop over array and use assertSame over assertEquals to prevent false positives
foreach ($originalEtags as $file => $originalEtag) {
$this->assertSame($originalEtag, $newEtags[$file]);
}
}
示例6: testNewUser
public function testNewUser()
{
$user1 = uniqid('user_');
$this->userBackend->createUser($user1, '');
\OC_Util::tearDownFS();
\OC_User::setUserId($user1);
\OC_Util::setupFS($user1);
Filesystem::mkdir('/folder');
Filesystem::mkdir('/folder/subfolder');
Filesystem::file_put_contents('/foo.txt', 'asd');
Filesystem::file_put_contents('/folder/bar.txt', 'fgh');
Filesystem::file_put_contents('/folder/subfolder/qwerty.txt', 'jkl');
$files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt');
$originalEtags = $this->getEtags($files);
$scanner = new \OC\Files\Utils\Scanner($user1);
$scanner->backgroundScan('/');
$newEtags = $this->getEtags($files);
// loop over array and use assertSame over assertEquals to prevent false positives
foreach ($originalEtags as $file => $originalEtag) {
$this->assertSame($originalEtag, $newEtags[$file]);
}
}
示例7: array
\OC\Files\Filesystem::mkdir($dir);
if (!\OC\Files\Filesystem::touch($dir . '/' . $file)) {
OCP\JSON::error(array("data" => array("message" => "Error when creating new file!")));
OCP\Util::writeLog('files_svgedit', "Failed to create file: " . $path, OC_Log::ERROR);
exit;
}
}
// file should be existing now
$writable = \OC\Files\Filesystem::isUpdatable($path);
if ($writable) {
if ($b64encoded) {
$b64prefix = 'data:' . $b64type . ';base64,';
if (strpos($filecontents, $b64prefix) === 0) {
$filecontents = base64_decode(substr($filecontents, strlen($b64prefix)));
}
}
\OC\Files\Filesystem::file_put_contents($path, $filecontents);
// Clear statcache
clearstatcache();
// Get new mtime
$newmtime = \OC\Files\Filesystem::filemtime($path);
OCP\JSON::success(array('data' => array('mtime' => $newmtime)));
} else {
// Not writable!
OCP\JSON::error(array('data' => array('message' => 'Insufficient permissions')));
OCP\Util::writeLog('files_svgedit', "User does not have permission to write to file: " . $path, OC_Log::ERROR);
}
} else {
OCP\JSON::error(array('data' => array('message' => 'File path or mtime not supplied')));
OCP\Util::writeLog('files_svgedit', "Invalid path supplied:" . $path, OC_Log::ERROR);
}
示例8: testCopy
function testCopy()
{
\OC\Files\Filesystem::file_put_contents("test.txt", "test file");
$t1 = time();
// second version is two weeks older, this way we make sure that no
// version will be expired
$t2 = $t1 - 60 * 60 * 24 * 14;
// create some versions
$v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1;
$v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2;
$v1Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1;
$v2Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2;
$this->rootView->file_put_contents($v1, 'version1');
$this->rootView->file_put_contents($v2, 'version2');
// execute copy hook of versions app
\OC\Files\Filesystem::copy("test.txt", "test2.txt");
$this->assertTrue($this->rootView->file_exists($v1));
$this->assertTrue($this->rootView->file_exists($v2));
$this->assertTrue($this->rootView->file_exists($v1Copied));
$this->assertTrue($this->rootView->file_exists($v2Copied));
//cleanup
\OC\Files\Filesystem::unlink('test.txt');
\OC\Files\Filesystem::unlink('test2.txt');
}
示例9: testPostDeleteMeta
public function testPostDeleteMeta()
{
$connector = new \OC\Files\Node\HookConnector($this->root, $this->view);
$connector->viewToNode();
$hookCalled = false;
/** @var Node $hookNode */
$hookNode = null;
$this->root->listen('\\OC\\Files', 'postDelete', function ($node) use(&$hookNode, &$hookCalled) {
$hookCalled = true;
$hookNode = $node;
});
Filesystem::file_put_contents('test.txt', 'asd');
$info = Filesystem::getFileInfo('test.txt');
Filesystem::unlink('test.txt');
$this->assertTrue($hookCalled);
$this->assertEquals($hookNode->getId(), $info->getId());
}
示例10: testTouchWithMountPoints
public function testTouchWithMountPoints() {
$storage2 = new \OC\Files\Storage\Temporary(array());
$cache2 = $storage2->getCache();
Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage');
Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd');
$this->assertTrue($cache2->inCache('foo.txt'));
$folderCachedData = $this->cache->get('folder');
$substorageCachedData = $cache2->get('');
$fooCachedData = $cache2->get('foo.txt');
$cachedData = $cache2->get('foo.txt');
$time = 1371006070;
$this->cache->put('folder', ['mtime' => $time - 100]);
Filesystem::touch('folder/substorage/foo.txt', $time);
$cachedData = $cache2->get('foo.txt');
$this->assertInternalType('string', $fooCachedData['etag']);
$this->assertInternalType('string', $cachedData['etag']);
$this->assertNotSame($fooCachedData['etag'], $cachedData['etag']);
$this->assertEquals($time, $cachedData['mtime']);
$cachedData = $cache2->get('');
$this->assertInternalType('string', $substorageCachedData['etag']);
$this->assertInternalType('string', $cachedData['etag']);
$this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']);
$cachedData = $this->cache->get('folder');
$this->assertInternalType('string', $folderCachedData['etag']);
$this->assertInternalType('string', $cachedData['etag']);
$this->assertNotSame($folderCachedData['etag'], $cachedData['etag']);
$this->assertEquals($time, $cachedData['mtime']);
}
示例11: viewToNodeProviderCopyRename
public function viewToNodeProviderCopyRename()
{
return [[function () {
Filesystem::file_put_contents('source', 'asd');
Filesystem::rename('source', 'target');
}, 'preRename'], [function () {
Filesystem::file_put_contents('source', 'asd');
Filesystem::rename('source', 'target');
}, 'postRename'], [function () {
Filesystem::file_put_contents('source', 'asd');
Filesystem::copy('source', 'target');
}, 'preCopy'], [function () {
Filesystem::file_put_contents('source', 'asd');
Filesystem::copy('source', 'target');
}, 'postCopy']];
}
示例12: testStoreVersionAsRecipient
/**
* Test whether versions are created when overwriting as share recipient
*/
public function testStoreVersionAsRecipient()
{
$this->loginAsUser(self::TEST_VERSIONS_USER);
\OC\Files\Filesystem::mkdir('folder');
\OC\Files\Filesystem::file_put_contents('folder/test.txt', 'test file');
$fileInfo = \OC\Files\Filesystem::getFileInfo('folder');
\OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, \OCP\Constants::PERMISSION_ALL);
$this->loginAsUser(self::TEST_VERSIONS_USER2);
$this->createAndCheckVersions(\OC\Files\Filesystem::getView(), 'folder/test.txt');
}
示例13: testShareWithGroupUniqueName
public function testShareWithGroupUniqueName()
{
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
\OC\Files\Filesystem::file_put_contents('test.txt', 'test');
$fileInfo = \OC\Files\Filesystem::getFileInfo('test.txt');
$this->assertTrue(\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1, 23));
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$items = \OCP\Share::getItemsSharedWith('file');
$this->assertSame('/test.txt', $items[0]['file_target']);
$this->assertSame(23, $items[0]['permissions']);
\OC\Files\Filesystem::rename('test.txt', 'new test.txt');
$items = \OCP\Share::getItemsSharedWith('file');
$this->assertSame('/new test.txt', $items[0]['file_target']);
$this->assertSame(23, $items[0]['permissions']);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
\OCP\Share::setPermissions('file', $items[0]['item_source'], $items[0]['share_type'], $items[0]['share_with'], 3);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$items = \OCP\Share::getItemsSharedWith('file');
$this->assertSame('/new test.txt', $items[0]['file_target']);
$this->assertSame(3, $items[0]['permissions']);
}
示例14: testMoveFileToFolder
/**
* @dataProvider usersProvider
*/
function testMoveFileToFolder($userId)
{
$view = new \OC\Files\View('/' . self::TEST_ENCRYPTION_SHARE_USER1);
$filename = '/tmp-' . $this->getUniqueID();
$folder = '/folder' . $this->getUniqueID();
\OC\Files\Filesystem::mkdir($folder);
// Save long data as encrypted file using stream wrapper
$cryptedFile = \OC\Files\Filesystem::file_put_contents($folder . $filename, $this->dataShort);
// Test that data was successfully written
$this->assertInternalType('int', $cryptedFile);
// Get file decrypted contents
$decrypt = \OC\Files\Filesystem::file_get_contents($folder . $filename);
$this->assertEquals($this->dataShort, $decrypt);
$subFolder = $folder . '/subfolder' . $this->getUniqueID();
\OC\Files\Filesystem::mkdir($subFolder);
// get the file info from previous created file
$fileInfo = \OC\Files\Filesystem::getFileInfo($folder);
$this->assertInstanceOf('\\OC\\Files\\FileInfo', $fileInfo);
// share the folder
\OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL);
// check that the share keys exist
$this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
$this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// move the file into the subfolder as the test user
self::loginHelper($userId);
\OC\Files\Filesystem::rename($folder . $filename, $subFolder . $filename);
self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
// Get file decrypted contents
$newDecrypt = \OC\Files\Filesystem::file_get_contents($subFolder . $filename);
$this->assertEquals($this->dataShort, $newDecrypt);
// check if additional share key for user2 exists
$this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
$this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// check that old keys were removed/moved properly
$this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
$this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// tear down
\OC\Files\Filesystem::unlink($subFolder);
\OC\Files\Filesystem::unlink($folder);
}
示例15: array
$result['data'] = array('message' => (string) $l10n->t('Incorrect padname.'));
OCP\JSON::error($result);
exit;
}
if (!OCP\Util::isValidFileName($padname)) {
$result['data'] = array('message' => (string) $l10n_files->t("Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed."));
OCP\JSON::error($result);
exit;
}
if (!\OC\Files\Filesystem::file_exists($dir . '/')) {
$result['data'] = array('message' => (string) $l10n_files->t('The target folder has been moved or deleted.'), 'code' => 'targetnotfound');
OCP\JSON::error($result);
exit;
}
// Add the extension only if padname doesn’t contain it
if (substr($padname, -strlen(".{$ext}")) != ".{$ext}") {
$filename = "{$padname}.{$ext}";
}
$target = $dir . "/" . $filename;
if (\OC\Files\Filesystem::file_exists($target)) {
$result['data'] = array('message' => (string) $l10n_files->t('The name %s is already used in the folder %s. Please choose a different name.', [$filename, $dir]));
OCP\JSON::error($result);
exit;
}
$content = sprintf("[InternetShortcut]\nURL=%s", $url);
if (\OC\Files\Filesystem::file_put_contents($target, $content)) {
$meta = \OC\Files\Filesystem::getFileInfo($target);
OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta)));
exit;
}
OCP\JSON::error(array('data' => array('message' => $l10n_files->t('Error when creating the file'))));