本文整理汇总了PHP中OC\Files\Filesystem类的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem类的具体用法?PHP Filesystem怎么用?PHP Filesystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Filesystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
public function tearDown()
{
foreach ($this->storages as $storage) {
$storage->getCache()->clear();
}
\OC\Files\Filesystem::clearMounts();
}
示例2: listdir
public static function listdir($dir, $dirs_stat)
{
$list = \OC\Files\Filesystem::getdirectorycontent($dir);
if (sizeof($list) > 0) {
$ret = '';
//$d=explode('/',$dir);
foreach ($list as $i) {
if ($i['type'] == 'dir' && $i['name'] != '.') {
if (!isset($i['directory'])) {
$i['directory'] = '';
}
$ret .= '<li class="ui-droppable">
<a href="./?app=files&dir=' . $i['directory'] . '/' . $i['name'] . '" data-pathname="' . $i['directory'] . '/' . $i['name'] . '">' . $i['name'] . '</a>' . listdir($dir . '/' . $i['name'], $dirs_stat) . '
</li>
';
}
}
if ($ret != '') {
$class = 'class="collapsed"';
if ($dir == '' || isset($dirs_stat[$dir]) && $dirs_stat[$dir] == 'expanded') {
$class = 'class="expanded"';
}
$ret = '<ul ' . $class . ' data-path="' . $dir . '"><li></li>' . $ret . '</ul>';
}
return $ret;
}
}
示例3: getFiles
public static function getFiles($dir, $sortAttribute = 'name', $sortDescending = false, $mimetypeFilter = '')
{
$contents = \OC\Files\Filesystem::getDirectoryContent($dir, $mimetypeFilter);
if (isset($_SESSION['targetType']) && $_SESSION['targetType'] == TargetType::PROJECT) {
/** @var FileInfo[] $subContents */
$subContents = [];
foreach ($contents as $content) {
/** @var FileInfo $content */
if ($content && $content->getMimetype() === 'httpd/unix-directory') {
$subDir = $dir . "/" . $content->getName();
$subContents = array_merge($subContents, \OC\Files\Filesystem::getDirectoryContent($subDir, $mimetypeFilter));
}
}
}
if (isset($subContents) && count($subContents) != 0) {
$contents = array_merge($contents, $subContents);
}
$excludeFolder = [];
foreach ($contents as $content) {
/** @var FileInfo $content */
if ($content && $content->getMimetype() === 'httpd/unix-directory') {
continue;
}
array_push($excludeFolder, $content);
}
return self::sortFiles($excludeFolder, $sortAttribute, $sortDescending);
}
示例4: propagateChange
/**
* @param string $internalPath
* @param int $time
* @return array[] all propagated entries
*/
public function propagateChange($internalPath, $time)
{
$source = $this->storage->getSourcePath($internalPath);
/** @var \OC\Files\Storage\Storage $storage */
list($storage, $sourceInternalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->getPropagator()->propagateChange($sourceInternalPath, $time);
}
示例5: setUp
protected function setUp()
{
parent::setUp();
$this->user = $this->getUniqueID();
$storage = new \OC\Files\Storage\Temporary(array());
\OC\Files\Filesystem::mount($storage, array(), '/' . $this->user . '/');
}
示例6: Add
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function Add()
{
\OCP\JSON::setContentTypeHeader('application/json');
if (isset($_POST['FILE']) && strlen($_POST['FILE']) > 0 && Tools::CheckURL($_POST['FILE']) && isset($_POST['OPTIONS'])) {
try {
$Target = Tools::CleanString(substr($_POST['FILE'], strrpos($_POST['FILE'], '/') + 1));
// If target file exists, create a new one
if (\OC\Files\Filesystem::file_exists($this->DownloadsFolder . '/' . $Target)) {
$Target = time() . '_' . $Target;
}
// Create the target file if the downloader is Aria2
if ($this->WhichDownloader == 0) {
\OC\Files\Filesystem::touch($this->DownloadsFolder . '/' . $Target);
} else {
if (!\OC\Files\Filesystem::is_dir($this->DownloadsFolder)) {
\OC\Files\Filesystem::mkdir($this->DownloadsFolder);
}
}
// Build OPTIONS array
$OPTIONS = array('dir' => $this->AbsoluteDownloadsFolder, 'out' => $Target, 'follow-torrent' => false);
if (isset($_POST['OPTIONS']['FTPUser']) && strlen(trim($_POST['OPTIONS']['FTPUser'])) > 0 && isset($_POST['OPTIONS']['FTPPasswd']) && strlen(trim($_POST['OPTIONS']['FTPPasswd'])) > 0) {
$OPTIONS['ftp-user'] = $_POST['OPTIONS']['FTPUser'];
$OPTIONS['ftp-passwd'] = $_POST['OPTIONS']['FTPPasswd'];
}
if (isset($_POST['OPTIONS']['FTPPasv']) && strlen(trim($_POST['OPTIONS']['FTPPasv'])) > 0) {
$OPTIONS['ftp-pasv'] = strcmp($_POST['OPTIONS']['FTPPasv'], "true") == 0 ? true : false;
}
if (!$this->ProxyOnlyWithYTDL && !is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) {
$OPTIONS['all-proxy'] = rtrim($this->ProxyAddress, '/') . ':' . $this->ProxyPort;
if (!is_null($this->ProxyUser) && !is_null($this->ProxyPasswd)) {
$OPTIONS['all-proxy-user'] = $this->ProxyUser;
$OPTIONS['all-proxy-passwd'] = $this->ProxyPasswd;
}
}
$AddURI = $this->WhichDownloader == 0 ? Aria2::AddUri(array($_POST['FILE']), array('Params' => $OPTIONS)) : CURL::AddUri($_POST['FILE'], $OPTIONS);
if (isset($AddURI['result']) && !is_null($AddURI['result'])) {
$SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?)';
if ($this->DbType == 1) {
$SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?)';
}
$Query = \OCP\DB::prepare($SQL);
$Result = $Query->execute(array($this->CurrentUID, $AddURI['result'], $Target, strtoupper(substr($_POST['FILE'], 0, strpos($_POST['FILE'], ':'))), 1, time()));
sleep(1);
$Status = $this->WhichDownloader == 0 ? Aria2::TellStatus($AddURI['result']) : CURL::TellStatus($AddURI['result']);
$Progress = 0;
if ($Status['result']['totalLength'] > 0) {
$Progress = $Status['result']['completedLength'] / $Status['result']['totalLength'];
}
$ProgressString = Tools::GetProgressString($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress);
return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('Download started'), 'GID' => $AddURI['result'], 'PROGRESSVAL' => round($Progress * 100, 2) . '%', 'PROGRESS' => is_null($ProgressString) ? (string) $this->L10N->t('N/A') : $ProgressString, 'STATUS' => isset($Status['result']['status']) ? (string) $this->L10N->t(ucfirst($Status['result']['status'])) : (string) $this->L10N->t('N/A'), 'STATUSID' => Tools::GetDownloadStatusID($Status['result']['status']), 'SPEED' => isset($Status['result']['downloadSpeed']) ? Tools::FormatSizeUnits($Status['result']['downloadSpeed']) . '/s' : (string) $this->L10N->t('N/A'), 'FILENAME' => strlen($Target) > 40 ? substr($Target, 0, 40) . '...' : $Target, 'PROTO' => strtoupper(substr($_POST['FILE'], 0, strpos($_POST['FILE'], ':'))), 'ISTORRENT' => false));
} else {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t($this->WhichDownloader == 0 ? 'Returned GID is null ! Is Aria2c running as a daemon ?' : 'An error occurred while running the CURL download')));
}
} catch (Exception $E) {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage()));
}
} else {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Please check the URL you\'ve just provided')));
}
}
示例7: initMountPointsHook
/**
* Hook that mounts the given user's visible mount points
* @param array $data
*/
public static function initMountPointsHook($data)
{
$mountPoints = self::getAbsoluteMountPoints($data['user']);
foreach ($mountPoints as $mountPoint => $options) {
\OC\Files\Filesystem::mount($options['class'], $options['options'], $mountPoint);
}
}
示例8: generateFileToken
public function generateFileToken($fileId, $version)
{
// Get the FS view of the current user.
$view = \OC\Files\Filesystem::getView();
// Get the virtual path (if the file is shared).
$path = $view->getPath($fileId);
if (!$view->is_file($path) || !$view->isUpdatable($path)) {
throw new \Exception('Invalid fileId.');
}
// Figure out the real owner, if not us.
$owner = $view->getOwner($path);
// Create a view into the owner's FS.
$view = new \OC\Files\View('/' . $owner . '/files');
// Find the real path.
$path = $view->getPath($fileId);
if (!$view->is_file($path)) {
throw new \Exception('Invalid fileId.');
}
$editor = \OC::$server->getUserSession()->getUser()->getUID();
$token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(32, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_UPPER . \OCP\Security\ISecureRandom::CHAR_DIGITS);
\OC::$server->getLogger()->debug('Issuing token for {editor} file {fileId}, version {version} owned by {owner}, path {path}: {token}', ['owner' => $owner, 'editor' => $editor, 'fileId' => $fileId, 'version' => $version, 'path' => $path, 'token' => $token]);
$wopi = new \OCA\Richdocuments\Db\Wopi([$owner, $editor, $fileId, $version, $path, $token, time() + self::TOKEN_LIFETIME_SECONDS]);
if (!$wopi->insert()) {
throw new \Exception('Failed to add wopi token into database');
}
return $token;
}
示例9: __construct
public function __construct($imagePath, $user = null, $square = false)
{
if (!Filesystem::isValidPath($imagePath)) {
return;
}
if (is_null($user)) {
$this->view = Filesystem::getView();
$this->user = \OCP\User::getUser();
} else {
$this->view = new View('/' . $user . '/files');
$this->user = $user;
}
$this->useOriginal = (substr($imagePath, -4) === '.svg' or substr($imagePath, -5) === '.svgz');
if ($this->useOriginal) {
$this->path = $imagePath;
} else {
$galleryDir = \OC_User::getHome($this->user) . '/gallery/' . $this->user . '/';
if (strrpos($imagePath, '.')) {
$extension = substr($imagePath, strrpos($imagePath, '.') + 1);
$image = substr($imagePath, 0, strrpos($imagePath, '.'));
} else {
$extension = '';
$image = $imagePath;
}
if ($square) {
$extension = 'square.' . $extension;
}
$this->path = $galleryDir . $image . '.' . $extension;
if (!file_exists($this->path)) {
$this->create($imagePath, $square);
}
}
}
示例10: checkUpdate
private static function checkUpdate($id)
{
$cacheItem = Cache::getById($id);
if (is_null($cacheItem)) {
return;
}
list($storageId, $internalPath) = $cacheItem;
$mounts = Filesystem::getMountByStorageId($storageId);
if (count($mounts) === 0) {
//if the storage we need isn't mounted on default, try to find a user that has access to the storage
$permissionsCache = new Permissions($storageId);
$users = $permissionsCache->getUsers($id);
if (count($users) === 0) {
return;
}
Filesystem::initMountPoints($users[0]);
$mounts = Filesystem::getMountByStorageId($storageId);
if (count($mounts) === 0) {
return;
}
}
$storage = $mounts[0]->getStorage();
$watcher = new Watcher($storage);
$watcher->checkUpdate($internalPath);
}
示例11: setUp
/**
* Make sure your configuration file doesn't contain any additional providers
*/
protected function setUp()
{
parent::setUp();
$userManager = \OC::$server->getUserManager();
$userManager->clearBackends();
$backend = new \Test\Util\User\Dummy();
$userManager->registerBackend($backend);
$backend->createUser(self::TEST_PREVIEW_USER1, self::TEST_PREVIEW_USER1);
$this->loginAsUser(self::TEST_PREVIEW_USER1);
$storage = new \OC\Files\Storage\Temporary([]);
\OC\Files\Filesystem::mount($storage, [], '/' . self::TEST_PREVIEW_USER1 . '/');
$this->rootView = new \OC\Files\View('');
$this->rootView->mkdir('/' . self::TEST_PREVIEW_USER1);
$this->rootView->mkdir('/' . self::TEST_PREVIEW_USER1 . '/files');
// We simulate the max dimension set in the config
\OC::$server->getConfig()->setSystemValue('preview_max_x', $this->configMaxWidth);
\OC::$server->getConfig()->setSystemValue('preview_max_y', $this->configMaxHeight);
// Used to test upscaling
$this->maxScaleFactor = 2;
\OC::$server->getConfig()->setSystemValue('preview_max_scale_factor', $this->maxScaleFactor);
// We need to enable the providers we're going to use in the tests
$providers = ['OC\\Preview\\JPEG', 'OC\\Preview\\PNG', 'OC\\Preview\\GIF', 'OC\\Preview\\TXT', 'OC\\Preview\\Postscript'];
\OC::$server->getConfig()->setSystemValue('enabledPreviewProviders', $providers);
// Sample is 1680x1050 JPEG
$this->prepareSample('testimage.jpg', 1680, 1050);
// Sample is 2400x1707 EPS
$this->prepareSample('testimage.eps', 2400, 1707);
// Sample is 1200x450 PNG
$this->prepareSample('testimage-wide.png', 1200, 450);
// Sample is 64x64 GIF
$this->prepareSample('testimage.gif', 64, 64);
}
示例12: setUp
protected function setUp()
{
parent::setUp();
if (!getenv('RUN_OBJECTSTORE_TESTS')) {
$this->markTestSkipped('objectstore tests are unreliable in some environments');
}
// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
// create users
$users = array('test');
foreach ($users as $userName) {
\OC_User::deleteUser($userName);
\OC_User::createUser($userName, $userName);
}
// main test user
\OC_Util::tearDownFS();
\OC_User::setUserId('');
\OC\Files\Filesystem::tearDown();
\OC_User::setUserId('test');
$config = \OC::$server->getConfig()->getSystemValue('objectstore');
$this->objectStorage = new ObjectStoreToTest($config['arguments']);
$config['objectstore'] = $this->objectStorage;
$this->instance = new ObjectStoreStorage($config);
}
示例13: propagateChanges
/**
* propagate the registered changes to their parent folders
*
* @param int $time (optional) the mtime to set for the folders, if not set the current time is used
*/
public function propagateChanges($time = null)
{
$changes = $this->getChanges();
$this->changedFiles = [];
if (!$time) {
$time = time();
}
foreach ($changes as $change) {
/**
* @var \OC\Files\Storage\Storage $storage
* @var string $internalPath
*/
$absolutePath = $this->view->getAbsolutePath($change);
$mount = $this->view->getMount($change);
$storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($absolutePath);
if ($storage) {
$propagator = $storage->getPropagator();
$propagatedEntries = $propagator->propagateChange($internalPath, $time);
foreach ($propagatedEntries as $entry) {
$absolutePath = Filesystem::normalizePath($mount->getMountPoint() . '/' . $entry['path']);
$relativePath = $this->view->getRelativePath($absolutePath);
$this->emit('\\OC\\Files', 'propagate', [$relativePath, $entry]);
}
}
}
}
示例14: search
/**
* Search for files and folders matching the given query
* @param string $query
* @return \OCP\Search\Result
*/
function search($query)
{
$files = Filesystem::search($query);
$results = array();
// edit results
foreach ($files as $fileData) {
// skip versions
if (strpos($fileData['path'], '_versions') === 0) {
continue;
}
// skip top-level folder
if ($fileData['name'] === 'files' && $fileData['parent'] === -1) {
continue;
}
// create audio result
if ($fileData['mimepart'] === 'audio') {
$result = new \OC\Search\Result\Audio($fileData);
} elseif ($fileData['mimepart'] === 'image') {
$result = new \OC\Search\Result\Image($fileData);
} elseif ($fileData['mimetype'] === 'httpd/unix-directory') {
$result = new \OC\Search\Result\Folder($fileData);
} else {
$result = new \OC\Search\Result\File($fileData);
}
// add to results
$results[] = $result;
}
// return
return $results;
}
示例15: 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;
}