本文整理汇总了PHP中OC\Files\View::file_get_contents方法的典型用法代码示例。如果您正苦于以下问题:PHP View::file_get_contents方法的具体用法?PHP View::file_get_contents怎么用?PHP View::file_get_contents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\View
的用法示例。
在下文中一共展示了View::file_get_contents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* load text file
*
* @NoAdminRequired
*
* @param string $dir
* @param string $filename
* @return DataResponse
*/
public function load($dir, $filename)
{
try {
if (!empty($filename)) {
$path = $dir . '/' . $filename;
$filecontents = $this->view->file_get_contents($path);
if ($filecontents !== false) {
$writable = $this->view->isUpdatable($path);
$mime = $this->view->getMimeType($path);
$mtime = $this->view->filemtime($path);
$encoding = mb_detect_encoding($filecontents . "a", "UTF-8, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII", true);
if ($encoding == "") {
// set default encoding if it couldn't be detected
$encoding = 'ISO-8859-15';
}
$filecontents = iconv($encoding, "UTF-8", $filecontents);
return new DataResponse(['filecontents' => $filecontents, 'writeable' => $writable, 'mime' => $mime, 'mtime' => $mtime], Http::STATUS_OK);
} else {
return new DataResponse(['message' => (string) $this->l->t('Can not read the file.')], Http::STATUS_BAD_REQUEST);
}
} else {
return new DataResponse(['message' => (string) $this->l->t('Invalid file path supplied.')], Http::STATUS_BAD_REQUEST);
}
} catch (\Exception $e) {
$hint = method_exists($e, 'getHint') ? $e->getHint() : $e->getMessage();
return new DataResponse(['message' => (string) $hint], Http::STATUS_BAD_REQUEST);
}
}
示例2: getAllVersions
/**
* Gets all versions of a note
*
* @NoAdminRequired
* @NoCSRFRequired
* @CORS
*
* @return array
*/
public function getAllVersions()
{
$source = $this->request->getParam("file_name", "");
list($uid, $filename) = Storage::getUidAndFilename($source);
$versions = Storage::getVersions($uid, $filename, $source);
$versionsResults = array();
if (is_array($versions) && count($versions) > 0) {
require_once __DIR__ . '/../3rdparty/finediff/finediff.php';
$users_view = new View('/' . $uid);
$currentData = $users_view->file_get_contents('files/' . $filename);
// $previousData = $currentData;
// $versions = array_reverse( $versions, true );
foreach ($versions as $versionData) {
// get timestamp of version
$mtime = (int) $versionData["version"];
// get filename of note version
$versionFileName = 'files_versions/' . $filename . '.v' . $mtime;
// load the data from the file
$data = $users_view->file_get_contents($versionFileName);
// calculate diff between versions
$opcodes = \FineDiff::getDiffOpcodes($currentData, $data);
$html = \FineDiff::renderDiffToHTMLFromOpcodes($currentData, $opcodes);
$versionsResults[] = array("timestamp" => $mtime, "humanReadableTimestamp" => $versionData["humanReadableTimestamp"], "diffHtml" => $html, "data" => $data);
// $previousData = $data;
}
// $versionsResults = array_reverse( $versionsResults );
}
return array("file_name" => $source, "versions" => $versionsResults);
}
示例3: get
/**
* get the users avatar
* @param int $size size in px of the avatar, avatars are square, defaults to 64
* @return boolean|\OCP\IImage containing the avatar or false if there's no image
*/
public function get($size = 64)
{
if ($this->view->file_exists('avatar.jpg')) {
$ext = 'jpg';
} elseif ($this->view->file_exists('avatar.png')) {
$ext = 'png';
} else {
return false;
}
$avatar = new OC_Image();
$avatar->loadFromData($this->view->file_get_contents('avatar.' . $ext));
$avatar->resize($size);
return $avatar;
}
示例4: createCertificateBundle
/**
* create the certificate bundle of all trusted certificated
*/
protected function createCertificateBundle()
{
$path = $this->getPathToCertificates();
$certs = $this->listCertificates();
$fh_certs = $this->view->fopen($path . '/rootcerts.crt', 'w');
foreach ($certs as $cert) {
$file = $path . '/uploads/' . $cert->getName();
$data = $this->view->file_get_contents($file);
if (strpos($data, 'BEGIN CERTIFICATE')) {
fwrite($fh_certs, $data);
fwrite($fh_certs, "\r\n");
}
}
fclose($fh_certs);
}
示例5: 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);
}
示例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: 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');
}
示例8: createCertificateBundle
/**
* create the certificate bundle of all trusted certificated
*/
public function createCertificateBundle()
{
$path = $this->getPathToCertificates();
$certs = $this->listCertificates();
if (!$this->view->file_exists($path)) {
$this->view->mkdir($path);
}
$fhCerts = $this->view->fopen($path . '/rootcerts.crt', 'w');
// Write user certificates
foreach ($certs as $cert) {
$file = $path . '/uploads/' . $cert->getName();
$data = $this->view->file_get_contents($file);
if (strpos($data, 'BEGIN CERTIFICATE')) {
fwrite($fhCerts, $data);
fwrite($fhCerts, "\r\n");
}
}
// Append the default certificates
$defaultCertificates = file_get_contents(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
fwrite($fhCerts, $defaultCertificates);
// Append the system certificate bundle
$systemBundle = $this->getCertificateBundle(null);
if ($this->view->file_exists($systemBundle)) {
$systemCertificates = $this->view->file_get_contents($systemBundle);
fwrite($fhCerts, $systemCertificates);
}
fclose($fhCerts);
}
示例9: testCreateMaxAndNormalPreviewsAtFirstRequest
/**
* Tests if a preview of max dimensions gets created
*
* @dataProvider dimensionsDataProvider
*
* @param int $sampleId
* @param int $widthAdjustment
* @param int $heightAdjustment
* @param bool $keepAspect
* @param bool $scalingUp
*/
public function testCreateMaxAndNormalPreviewsAtFirstRequest(
$sampleId, $widthAdjustment, $heightAdjustment, $keepAspect = false, $scalingUp = false
) {
//$this->markTestSkipped('Not testing this at this time');
// Get the right sample for the experiment
$this->getSample($sampleId);
$sampleWidth = $this->sampleWidth;
$sampleHeight = $this->sampleHeight;
$sampleFileId = $this->sampleFileId;
// Adjust the requested size so that we trigger various test cases
$previewWidth = $sampleWidth + $widthAdjustment;
$previewHeight = $sampleHeight + $heightAdjustment;
$this->keepAspect = $keepAspect;
$this->scalingUp = $scalingUp;
// Generates the max preview
$preview = $this->createPreview($previewWidth, $previewHeight);
// There should be no cached thumbnails
$thumbnailFolder = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER .
'/' . $sampleFileId;
$this->assertSame(false, $this->rootView->is_dir($thumbnailFolder));
$image = $preview->getPreview();
$this->assertNotSame(false, $image);
$maxThumbCacheFile = $this->buildCachePath(
$sampleFileId, $this->maxPreviewWidth, $this->maxPreviewHeight, true, '-max'
);
$this->assertSame(
true, $this->rootView->file_exists($maxThumbCacheFile), "$maxThumbCacheFile \n"
);
// We check the dimensions of the file we've just stored
$maxPreview = imagecreatefromstring($this->rootView->file_get_contents($maxThumbCacheFile));
$this->assertEquals($this->maxPreviewWidth, imagesx($maxPreview));
$this->assertEquals($this->maxPreviewHeight, imagesy($maxPreview));
// A thumbnail of the asked dimensions should also have been created (within the constraints of the max preview)
list($limitedPreviewWidth, $limitedPreviewHeight) =
$this->simulatePreviewDimensions($previewWidth, $previewHeight);
$actualWidth = $image->width();
$actualHeight = $image->height();
$this->assertEquals(
(int)$limitedPreviewWidth, $image->width(), "$actualWidth x $actualHeight \n"
);
$this->assertEquals((int)$limitedPreviewHeight, $image->height());
// And it should be cached
$this->checkCache($sampleFileId, $limitedPreviewWidth, $limitedPreviewHeight);
$preview->deleteAllPreviews();
}
示例10: load
/**
* load text file
*
* @NoAdminRequired
*
* @param string $dir
* @param string $filename
* @return DataResponse
*/
public function load($dir, $filename)
{
try {
if (!empty($filename)) {
$path = $dir . '/' . $filename;
// default of 4MB
$maxSize = 4194304;
if ($this->view->filesize($path) > $maxSize) {
return new DataResponse(['message' => (string) $this->l->t('This file is too big to be opened. Please download the file instead.')], Http::STATUS_BAD_REQUEST);
}
$fileContents = $this->view->file_get_contents($path);
if ($fileContents !== false) {
$writable = $this->view->isUpdatable($path);
$mime = $this->view->getMimeType($path);
$mTime = $this->view->filemtime($path);
$encoding = mb_detect_encoding($fileContents . "a", "UTF-8, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII", true);
if ($encoding == "") {
// set default encoding if it couldn't be detected
$encoding = 'ISO-8859-15';
}
$fileContents = iconv($encoding, "UTF-8", $fileContents);
return new DataResponse(['filecontents' => $fileContents, 'writeable' => $writable, 'mime' => $mime, 'mtime' => $mTime], Http::STATUS_OK);
} else {
return new DataResponse(['message' => (string) $this->l->t('Cannot read the file.')], Http::STATUS_BAD_REQUEST);
}
} else {
return new DataResponse(['message' => (string) $this->l->t('Invalid file path supplied.')], Http::STATUS_BAD_REQUEST);
}
} catch (LockedException $e) {
$message = (string) $this->l->t('The file is locked.');
return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
} catch (ForbiddenException $e) {
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
} catch (HintException $e) {
$message = (string) $e->getHint();
return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
} catch (\Exception $e) {
$message = (string) $this->l->t('An internal server error occurred.');
return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
}
}
示例11: getPrivateKey
/**
* @brief retrieve the ENCRYPTED private key from a user
*
* @param \OC\Files\View $view
* @param string $user
* @return string private key or false (hopefully)
* @note the key returned by this method must be decrypted before use
*/
public static function getPrivateKey($view, $user)
{
$path = '/' . $user . '/' . 'files_encryption' . '/' . $user . '.private.key';
$key = false;
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
if ($view->file_exists($path)) {
$key = $view->file_get_contents($path);
}
\OC_FileProxy::$enabled = $proxyStatus;
return $key;
}
示例12: getKey
/**
* read key from hard disk
*
* @param string $path to key
* @return string
*/
private function getKey($path)
{
$key = '';
if ($this->view->file_exists($path)) {
if (isset($this->keyCache[$path])) {
$key = $this->keyCache[$path];
} else {
$key = $this->view->file_get_contents($path);
$this->keyCache[$path] = $key;
}
}
return $key;
}
示例13: testGetFileSize
/**
* Test that data that is read by the crypto stream wrapper
*/
function testGetFileSize()
{
self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1);
$filename = 'tmp-' . $this->getUniqueID();
$externalFilename = '/' . $this->userId . '/files/' . $filename;
// Test for 0 byte files
$problematicFileSizeData = "";
$cryptedFile = $this->view->file_put_contents($externalFilename, $problematicFileSizeData);
$this->assertTrue(is_int($cryptedFile));
$this->assertEquals($this->util->getFileSize($externalFilename), 0);
$decrypt = $this->view->file_get_contents($externalFilename);
$this->assertEquals($problematicFileSizeData, $decrypt);
$this->view->unlink($this->userId . '/files/' . $filename);
// Test a file with 18377 bytes as in https://github.com/owncloud/mirall/issues/1009
$problematicFileSizeData = str_pad("", 18377, "abc");
$cryptedFile = $this->view->file_put_contents($externalFilename, $problematicFileSizeData);
$this->assertTrue(is_int($cryptedFile));
$this->assertEquals($this->util->getFileSize($externalFilename), 18377);
$decrypt = $this->view->file_get_contents($externalFilename);
$this->assertEquals($problematicFileSizeData, $decrypt);
$this->view->unlink($this->userId . '/files/' . $filename);
}
示例14: testRename
/**
* test rename a shared file mount point
*/
function testRename()
{
// login as admin
self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
// save file with content
$cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);
// test that data was successfully written
$this->assertInternalType('int', $cryptedFile);
// get the file info from previous created file
$fileInfo = $this->view->getFileInfo('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
// check if we have a valid file info
$this->assertInstanceOf('\\OC\\Files\\FileInfo', $fileInfo);
// share the file
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL);
// check if share key for user1 and user2 exists
$this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
$this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// login as user2
self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2);
$this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename));
// get file contents
$retrievedCryptedFile = $this->view->file_get_contents('/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
// check if data is the same as we previously written
$this->assertEquals($this->dataShort, $retrievedCryptedFile);
\OC\Files\Filesystem::mkdir($this->folder1);
// move the file to a subfolder
\OC\Files\Filesystem::rename($this->filename, $this->folder1 . $this->filename);
// check if we can read the moved file
$retrievedRenamedFile = $this->view->file_get_contents('/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->filename);
// check if data is the same as we previously written
$this->assertEquals($this->dataShort, $retrievedRenamedFile);
// check if share key for user2 and user1 still exists
$this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
$this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
$this->view->unlink('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
}
示例15: testWebdavPUT
/**
* test webdav put random file
*/
function testWebdavPUT()
{
// generate filename
$filename = '/tmp-' . uniqid() . '.txt';
// set server vars
$_SERVER['REQUEST_METHOD'] = 'OPTIONS';
$_SERVER['REQUEST_METHOD'] = 'PUT';
$_SERVER['REQUEST_URI'] = '/remote.php/webdav' . $filename;
$_SERVER['HTTP_AUTHORIZATION'] = 'Basic dGVzdC13ZWJkYXYtdXNlcjE6dGVzdC13ZWJkYXYtdXNlcjE=';
$_SERVER['CONTENT_TYPE'] = 'application/octet-stream';
$_SERVER['PATH_INFO'] = '/webdav' . $filename;
$_SERVER['CONTENT_LENGTH'] = strlen($this->dataShort);
// handle webdav request
$this->handleWebdavRequest($this->dataShort);
// check if file was created
$this->assertTrue($this->view->file_exists('/' . $this->userId . '/files' . $filename));
// check if key-file was created
$this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/keyfiles/' . $filename . '.key'));
// check if shareKey-file was created
$this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/share-keys/' . $filename . '.' . $this->userId . '.shareKey'));
// disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
// get encrypted file content
$encryptedContent = $this->view->file_get_contents('/' . $this->userId . '/files' . $filename);
// restore proxy state
\OC_FileProxy::$enabled = $proxyStatus;
// check if encrypted content is valid
$this->assertTrue(Encryption\Crypt::isCatfileContent($encryptedContent));
// get decrypted file contents
$decrypt = file_get_contents('crypt:///' . $this->userId . '/files' . $filename);
// check if file content match with the written content
$this->assertEquals($this->dataShort, $decrypt);
// return filename for next test
return $filename;
}