本文整理汇总了PHP中OC\Files\Filesystem::isValidPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::isValidPath方法的具体用法?PHP Filesystem::isValidPath怎么用?PHP Filesystem::isValidPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\Filesystem
的用法示例。
在下文中一共展示了Filesystem::isValidPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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);
}
}
}
示例2: __construct
/**
* constructor
* @param string $user user to do avatar-management with
* @throws \Exception In case the username is potentially dangerous
*/
public function __construct($user)
{
if (!Filesystem::isValidPath($user)) {
throw new \Exception('Username may not contain slashes');
}
$this->view = new \OC\Files\View('/' . $user);
}
示例3: indexFile
/**
* index a file
*
* @author Jörn Dreyer <jfd@butonic.de>
*
* @param string $path the path of the file
*
* @return bool
*/
public static function indexFile($path = '', $user = null)
{
if (!Filesystem::isValidPath($path)) {
return;
}
if ($path === '') {
//ignore the empty path element
return false;
}
if (is_null($user)) {
$view = Filesystem::getView();
$user = \OCP\User::getUser();
} else {
$view = new \OC\Files\View('/' . $user . '/files');
}
if (!$view) {
Util::writeLog('search_lucene', 'could not resolve filesystem view', Util::WARN);
return false;
}
$root = $view->getRoot();
$pk = md5($root . $path);
// the cache already knows mime and other basic stuff
$data = $view->getFileInfo($path);
if (isset($data['mimetype'])) {
$mimetype = $data['mimetype'];
if ('text/html' === $mimetype) {
$doc = \Zend_Search_Lucene_Document_Html::loadHTML($view->file_get_contents($path));
} else {
if ('application/msword' === $mimetype) {
// FIXME uses ZipArchive ... make compatible with OC\Files\Filesystem
//$doc = Zend_Search_Lucene_Document_Docx::loadDocxFile(OC\Files\Filesystem::file_get_contents($path));
//no special treatment yet
$doc = new \Zend_Search_Lucene_Document();
} else {
$doc = new \Zend_Search_Lucene_Document();
}
}
// store fscacheid as unique id to lookup by when deleting
$doc->addField(\Zend_Search_Lucene_Field::Keyword('pk', $pk));
// Store document URL to identify it in the search results
$doc->addField(\Zend_Search_Lucene_Field::Text('path', $path));
$doc->addField(\Zend_Search_Lucene_Field::unIndexed('size', $data['size']));
$doc->addField(\Zend_Search_Lucene_Field::unIndexed('mimetype', $mimetype));
self::extractMetadata($doc, $path, $view, $mimetype);
Lucene::updateFile($doc, $path, $user);
return true;
} else {
Util::writeLog('search_lucene', 'need mimetype for content extraction', Util::ERROR);
return false;
}
}
示例4: 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;
}
示例5: __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;
}
$galleryDir = \OC_User::getHome($this->user) . '/gallery/' . $this->user . '/';
$this->path = $galleryDir . $imagePath . '.png';
if (!file_exists($this->path)) {
self::create($imagePath, $square);
}
}
示例6: indexFile
/**
* index a file
*
* @author Jörn Dreyer <jfd@butonic.de>
*
* @param string $path the path of the file
*
* @return bool
*/
public static function indexFile($path = '', $user = null)
{
if (!Filesystem::isValidPath($path)) {
return;
}
if ($path === '') {
//ignore the empty path element
return false;
}
if (is_null($user)) {
$view = Filesystem::getView();
$user = \OCP\User::getUser();
} else {
$view = new \OC\Files\View('/' . $user . '/files');
}
if (!$view) {
Util::writeLog('search_lucene', 'could not resolve filesystem view', Util::WARN);
return false;
}
if (!$view->file_exists($path)) {
Util::writeLog('search_lucene', 'file vanished, ignoring', Util::DEBUG);
return true;
}
$root = $view->getRoot();
$pk = md5($root . $path);
// the cache already knows mime and other basic stuff
$data = $view->getFileInfo($path);
if (isset($data['mimetype'])) {
$mimeType = $data['mimetype'];
// initialize plain lucene document
$doc = new \Zend_Search_Lucene_Document();
// index content for local files only
$localFile = $view->getLocalFile($path);
if ($localFile) {
//try to use special lucene document types
if ('text/plain' === $mimeType) {
$body = $view->file_get_contents($path);
if ($body != '') {
$doc->addField(\Zend_Search_Lucene_Field::UnStored('body', $body));
}
} else {
if ('text/html' === $mimeType) {
//TODO could be indexed, even if not local
$doc = \Zend_Search_Lucene_Document_Html::loadHTML($view->file_get_contents($path));
} else {
if ('application/pdf' === $mimeType) {
$doc = Pdf::loadPdf($view->file_get_contents($path));
// commented the mimetype checks, as the zend classes only understand docx and not doc files.
// FIXME distinguish doc and docx, xls and xlsx, ppt and pptx, in oc core mimetype helper ...
//} else if ('application/msword' === $mimeType) {
} else {
if (strtolower(substr($data['name'], -5)) === '.docx') {
$doc = \Zend_Search_Lucene_Document_Docx::loadDocxFile($localFile);
//} else if ('application/msexcel' === $mimeType) {
} else {
if (strtolower(substr($data['name'], -5)) === '.xlsx') {
$doc = \Zend_Search_Lucene_Document_Xlsx::loadXlsxFile($localFile);
//} else if ('application/mspowerpoint' === $mimeType) {
} else {
if (strtolower(substr($data['name'], -5)) === '.pptx') {
$doc = \Zend_Search_Lucene_Document_Pptx::loadPptxFile($localFile);
} else {
if (strtolower(substr($data['name'], -4)) === '.odt') {
$doc = Odt::loadOdtFile($localFile);
} else {
if (strtolower(substr($data['name'], -4)) === '.ods') {
$doc = Ods::loadOdsFile($localFile);
}
}
}
}
}
}
}
}
}
// Store filecache id as unique id to lookup by when deleting
$doc->addField(\Zend_Search_Lucene_Field::Keyword('pk', $pk));
// Store filename
$doc->addField(\Zend_Search_Lucene_Field::Text('filename', $data['name'], 'UTF-8'));
// Store document path to identify it in the search results
$doc->addField(\Zend_Search_Lucene_Field::Text('path', $path, 'UTF-8'));
$doc->addField(\Zend_Search_Lucene_Field::unIndexed('size', $data['size']));
$doc->addField(\Zend_Search_Lucene_Field::unIndexed('mimetype', $mimeType));
//self::extractMetadata($doc, $path, $view, $mimeType);
Lucene::updateFile($doc, $path, $user);
return true;
} else {
Util::writeLog('search_lucene', 'need mimetype for content extraction', Util::ERROR);
return false;
}
//.........这里部分代码省略.........
示例7: testIsValidPath
/**
* @dataProvider isValidPathData
*/
public function testIsValidPath($path, $expected)
{
$this->assertSame($expected, \OC\Files\Filesystem::isValidPath($path));
}
示例8: getDirectoryContent
/**
* get the content of a directory
*
* @param string $directory path under datadirectory
* @param string $mimetype_filter limit returned content to this mimetype or mimepart
* @return FileInfo[]
*/
public function getDirectoryContent($directory, $mimetype_filter = '')
{
$this->assertPathLength($directory);
$result = array();
if (!Filesystem::isValidPath($directory)) {
return $result;
}
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $directory);
list($storage, $internalPath) = Filesystem::resolvePath($path);
if ($storage) {
$cache = $storage->getCache($internalPath);
$user = \OC_User::getUser();
if ($cache->getStatus($internalPath) < Cache\Cache::COMPLETE) {
$scanner = $storage->getScanner($internalPath);
$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
} else {
$watcher = $storage->getWatcher($internalPath);
$watcher->checkUpdate($internalPath);
}
$folderId = $cache->getId($internalPath);
/**
* @var \OC\Files\FileInfo[] $files
*/
$files = array();
$contents = $cache->getFolderContents($internalPath, $folderId);
//TODO: mimetype_filter
foreach ($contents as $content) {
if ($content['permissions'] === 0) {
$content['permissions'] = $storage->getPermissions($content['path']);
$cache->update($content['fileid'], array('permissions' => $content['permissions']));
}
$files[] = new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content);
}
//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
$mounts = Filesystem::getMountManager()->findIn($path);
$dirLength = strlen($path);
foreach ($mounts as $mount) {
$mountPoint = $mount->getMountPoint();
$subStorage = Filesystem::getStorage($mountPoint);
if ($subStorage) {
$subCache = $subStorage->getCache('');
if ($subCache->getStatus('') === Cache\Cache::NOT_FOUND) {
$subScanner = $subStorage->getScanner('');
$subScanner->scanFile('');
}
$rootEntry = $subCache->get('');
if ($rootEntry) {
$relativePath = trim(substr($mountPoint, $dirLength), '/');
if ($pos = strpos($relativePath, '/')) {
//mountpoint inside subfolder add size to the correct folder
$entryName = substr($relativePath, 0, $pos);
foreach ($files as &$entry) {
if ($entry['name'] === $entryName) {
$entry['size'] += $rootEntry['size'];
}
}
} else {
//mountpoint in this folder, add an entry for it
$rootEntry['name'] = $relativePath;
$rootEntry['type'] = $rootEntry['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
$permissions = $rootEntry['permissions'];
// do not allow renaming/deleting the mount point if they are not shared files/folders
// for shared files/folders we use the permissions given by the owner
if ($mount instanceof MoveableMount) {
$rootEntry['permissions'] = $permissions | \OCP\PERMISSION_UPDATE | \OCP\PERMISSION_DELETE;
} else {
$rootEntry['permissions'] = $permissions & \OCP\PERMISSION_ALL - (\OCP\PERMISSION_UPDATE | \OCP\PERMISSION_DELETE);
}
//remove any existing entry with the same name
foreach ($files as $i => $file) {
if ($file['name'] === $rootEntry['name']) {
unset($files[$i]);
break;
}
}
$rootEntry['path'] = substr($path . '/' . $rootEntry['name'], strlen($user) + 2);
// full path without /$user/
$files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry);
}
}
}
}
if ($mimetype_filter) {
foreach ($files as $file) {
if (strpos($mimetype_filter, '/')) {
if ($file['mimetype'] === $mimetype_filter) {
$result[] = $file;
}
} else {
if ($file['mimepart'] === $mimetype_filter) {
$result[] = $file;
}
}
//.........这里部分代码省略.........
示例9: removeCertificate
/**
* Remove the certificate and re-generate the certificate bundle
*
* @param string $name
* @return bool
*/
public function removeCertificate($name)
{
if (!Filesystem::isValidPath($name)) {
return false;
}
$path = $this->getPathToCertificates() . 'uploads/';
if ($this->view->file_exists($path . $name)) {
$this->view->unlink($path . $name);
$this->createCertificateBundle();
}
return true;
}
示例10: getDirectoryContent
/**
* get the content of a directory
*
* @param string $directory path under datadirectory
* @param string $mimetype_filter limit returned content to this mimetype or mimepart
* @return FileInfo[]
*/
public function getDirectoryContent($directory, $mimetype_filter = '')
{
$this->assertPathLength($directory);
$result = array();
if (!Filesystem::isValidPath($directory)) {
return $result;
}
$path = $this->getAbsolutePath($directory);
$path = Filesystem::normalizePath($path);
$mount = $this->getMount($directory);
$storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($path);
if ($storage) {
$cache = $storage->getCache($internalPath);
$user = \OC_User::getUser();
$data = $cache->get($internalPath);
$watcher = $storage->getWatcher($internalPath);
if (!$data or $data['size'] === -1) {
if (!$storage->file_exists($internalPath)) {
return array();
}
$scanner = $storage->getScanner($internalPath);
$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
$data = $cache->get($internalPath);
} else {
if ($watcher->checkUpdate($internalPath, $data)) {
$this->updater->propagate($path);
$data = $cache->get($internalPath);
}
}
$folderId = $data['fileid'];
/**
* @var \OC\Files\FileInfo[] $files
*/
$files = array();
$contents = $cache->getFolderContentsById($folderId);
//TODO: mimetype_filter
foreach ($contents as $content) {
if ($content['permissions'] === 0) {
$content['permissions'] = $storage->getPermissions($content['path']);
$cache->update($content['fileid'], array('permissions' => $content['permissions']));
}
// if sharing was disabled for the user we remove the share permissions
if (\OCP\Util::isSharingDisabledForUser()) {
$content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
}
$files[] = new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content, $mount);
}
//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
$mounts = Filesystem::getMountManager()->findIn($path);
$dirLength = strlen($path);
foreach ($mounts as $mount) {
$mountPoint = $mount->getMountPoint();
$subStorage = $mount->getStorage();
if ($subStorage) {
$subCache = $subStorage->getCache('');
if ($subCache->getStatus('') === Cache\Cache::NOT_FOUND) {
$subScanner = $subStorage->getScanner('');
try {
$subScanner->scanFile('');
} catch (\OCP\Files\StorageNotAvailableException $e) {
continue;
} catch (\OCP\Files\StorageInvalidException $e) {
continue;
} catch (\Exception $e) {
// sometimes when the storage is not available it can be any exception
\OCP\Util::writeLog('core', 'Exception while scanning storage "' . $subStorage->getId() . '": ' . get_class($e) . ': ' . $e->getMessage(), \OCP\Util::ERROR);
continue;
}
}
$rootEntry = $subCache->get('');
if ($rootEntry) {
$relativePath = trim(substr($mountPoint, $dirLength), '/');
if ($pos = strpos($relativePath, '/')) {
//mountpoint inside subfolder add size to the correct folder
$entryName = substr($relativePath, 0, $pos);
foreach ($files as &$entry) {
if ($entry['name'] === $entryName) {
$entry['size'] += $rootEntry['size'];
}
}
} else {
//mountpoint in this folder, add an entry for it
$rootEntry['name'] = $relativePath;
$rootEntry['type'] = $rootEntry['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
$permissions = $rootEntry['permissions'];
// do not allow renaming/deleting the mount point if they are not shared files/folders
// for shared files/folders we use the permissions given by the owner
if ($mount instanceof MoveableMount) {
$rootEntry['permissions'] = $permissions | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
} else {
$rootEntry['permissions'] = $permissions & \OCP\Constants::PERMISSION_ALL - (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE);
}
//.........这里部分代码省略.........
示例11: scan
/**
* @param string $dir
* @throws \OC\ForbiddenException
*/
public function scan($dir = '')
{
if (!Filesystem::isValidPath($dir)) {
throw new \InvalidArgumentException('Invalid path to scan');
}
$mounts = $this->getMounts($dir);
foreach ($mounts as $mount) {
if (is_null($mount->getStorage())) {
continue;
}
$storage = $mount->getStorage();
// if the home storage isn't writable then the scanner is run as the wrong user
if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Home') and (!$storage->isCreatable('') or !$storage->isCreatable('files'))) {
throw new ForbiddenException();
}
$relativePath = $mount->getInternalPath($dir);
$scanner = $storage->getScanner();
$scanner->setUseTransactions(false);
$this->attachListener($mount);
$this->db->beginTransaction();
$scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
$this->db->commit();
}
$this->propagator->propagateChanges(time());
}
示例12: foreach
}
}
$files = $_FILES['files'];
$error = false;
$maxUploadFileSize = $storageStats['uploadMaxFilesize'];
$maxHumanFileSize = OCP\Util::humanFileSize($maxUploadFileSize);
$totalSize = 0;
foreach ($files['size'] as $size) {
$totalSize += $size;
}
if ($maxUploadFileSize >= 0 and $totalSize > $maxUploadFileSize) {
OCP\JSON::error(array('data' => array('message' => $l->t('Not enough storage available'), 'uploadMaxFilesize' => $maxUploadFileSize, 'maxHumanFilesize' => $maxHumanFileSize)));
exit;
}
$result = array();
if (\OC\Files\Filesystem::isValidPath($dir) === true) {
$fileCount = count($files['name']);
for ($i = 0; $i < $fileCount; $i++) {
if (isset($_POST['resolution'])) {
$resolution = $_POST['resolution'];
} else {
$resolution = null;
}
// target directory for when uploading folders
$relativePath = '';
if (!empty($_POST['file_directory'])) {
$relativePath = '/' . $_POST['file_directory'];
}
// $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder
if ($resolution === 'autorename') {
// append a number in brackets like 'filename (2).ext'
示例13: isValidPath
/**
* check if the requested path is valid
*
* @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
* @param string $path
* @return bool
*/
public static function isValidPath($path)
{
return \OC\Files\Filesystem::isValidPath($path);
}
示例14: removeCertificate
/**
* Remove the certificate and re-generate the certificate bundle
*
* @param string $name
* @return bool
*/
public function removeCertificate($name)
{
if (!Filesystem::isValidPath($name)) {
return false;
}
$path = $this->user->getHome() . '/files_external/uploads/';
if (file_exists($path . $name)) {
unlink($path . $name);
$this->createCertificateBundle();
}
return true;
}
示例15: file_assemble
/**
* Assembles the chunks into the file specified by the path.
* Also triggers the relevant hooks and proxies.
*
* @param \OC\Files\Storage\Storage $storage storage
* @param string $path target path relative to the storage
* @return bool true on success or false if file could not be created
*
* @throws \OC\ServerNotAvailableException
*/
public function file_assemble($storage, $path)
{
// use file_put_contents as method because that best matches what this function does
if (\OC\Files\Filesystem::isValidPath($path)) {
$target = $storage->fopen($path, 'w');
if ($target) {
$count = $this->assemble($target);
fclose($target);
return $count > 0;
} else {
return false;
}
}
return false;
}