本文整理汇总了PHP中OCP\Files类的典型用法代码示例。如果您正苦于以下问题:PHP Files类的具体用法?PHP Files怎么用?PHP Files使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Files类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: update
public static function update($version, $backupBase)
{
if (!is_dir($backupBase)) {
throw new \Exception("Backup directory {$backupBase} is not found");
}
set_include_path($backupBase . PATH_SEPARATOR . $backupBase . '/core/lib' . PATH_SEPARATOR . $backupBase . '/core/config' . PATH_SEPARATOR . $backupBase . '/3rdparty' . PATH_SEPARATOR . $backupBase . '/apps' . PATH_SEPARATOR . get_include_path());
$tempDir = self::getTempDir();
Helper::mkdir($tempDir, true);
$installed = Helper::getDirectories();
$sources = Helper::getSources($version);
try {
$thirdPartyUpdater = new Location_3rdparty($installed[Helper::THIRDPARTY_DIRNAME], $sources[Helper::THIRDPARTY_DIRNAME]);
$thirdPartyUpdater->update($tempDir . '/' . Helper::THIRDPARTY_DIRNAME);
self::$processed[] = $thirdPartyUpdater;
$coreUpdater = new Location_Core($installed[Helper::CORE_DIRNAME], $sources[Helper::CORE_DIRNAME]);
$coreUpdater->update($tempDir . '/' . Helper::CORE_DIRNAME);
self::$processed[] = $coreUpdater;
$appsUpdater = new Location_Apps('', $sources[Helper::APP_DIRNAME]);
$appsUpdater->update($tempDir . '/' . Helper::APP_DIRNAME);
self::$processed[] = $appsUpdater;
} catch (\Exception $e) {
self::rollBack();
self::cleanUp();
throw $e;
}
// zip backup
$zip = new \ZipArchive();
if ($zip->open($backupBase . ".zip", \ZIPARCHIVE::CREATE) === true) {
Helper::addDirectoryToZip($zip, $backupBase, $backupBase);
$zip->close();
\OCP\Files::rmdirr($backupBase);
}
return true;
}
开发者ID:omusico,项目名称:isle-web-framework,代码行数:34,代码来源:updater.php
示例2: createShare
/**
* create a new share
*
* @param array $params
* @return \OC_OCS_Result
*/
public function createShare($params)
{
if (!$this->isS2SEnabled(true)) {
return new \OC_OCS_Result(null, 503, 'Server does not support server-to-server sharing');
}
$remote = isset($_POST['remote']) ? $_POST['remote'] : null;
$token = isset($_POST['token']) ? $_POST['token'] : null;
$name = isset($_POST['name']) ? $_POST['name'] : null;
$owner = isset($_POST['owner']) ? $_POST['owner'] : null;
$shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
$remoteId = isset($_POST['remoteId']) ? (int) $_POST['remoteId'] : null;
if ($remote && $token && $name && $owner && $remoteId && $shareWith) {
if (!\OCP\Util::isValidFileName($name)) {
return new \OC_OCS_Result(null, 400, 'The mountpoint name contains invalid characters.');
}
if (!\OCP\User::userExists($shareWith)) {
return new \OC_OCS_Result(null, 400, 'User does not exists');
}
\OC_Util::setupFS($shareWith);
$externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getUserSession(), \OC::$server->getHTTPHelper());
$name = \OCP\Files::buildNotExistingFileName('/', $name);
try {
$externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
$user = $owner . '@' . $this->cleanupRemote($remote);
\OC::$server->getActivityManager()->publishActivity('files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($user), '', array(), '', '', $shareWith, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW);
return new \OC_OCS_Result();
} catch (\Exception $e) {
\OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR);
return new \OC_OCS_Result(null, 500, 'internal server error, was not able to add share from ' . $remote);
}
}
return new \OC_OCS_Result(null, 400, 'server can not add remote share, missing parameter');
}
开发者ID:riso,项目名称:owncloud-core,代码行数:39,代码来源:server2server.php
示例3: tearDown
protected function tearDown()
{
if ($this->instance) {
\OCP\Files::rmdirr($this->instance->constructUrl(''));
}
parent::tearDown();
}
开发者ID:kebenxiaoming,项目名称:owncloudRedis,代码行数:7,代码来源:smb.php
示例4: show
/**
* Get the template for a specific activity-event in the activities
*
* @param array $activity An array with all the activity data in it
* @return string
*/
public function show($activity)
{
$tmpl = new Template('activity', 'stream.item');
$tmpl->assign('formattedDate', $this->dateTimeFormatter->formatDateTime($activity['timestamp']));
$tmpl->assign('formattedTimestamp', Template::relative_modified_date($activity['timestamp']));
if (strpos($activity['subjectformatted']['markup']['trimmed'], '<a ') !== false) {
// We do not link the subject as we create links for the parameters instead
$activity['link'] = '';
}
$tmpl->assign('event', $activity);
if ($activity['file']) {
$this->view->chroot('/' . $activity['affecteduser'] . '/files');
$exist = $this->view->file_exists($activity['file']);
$is_dir = $this->view->is_dir($activity['file']);
$tmpl->assign('previewLink', $this->getPreviewLink($activity['file'], $is_dir));
// show a preview image if the file still exists
$mimeType = Files::getMimeType($activity['file']);
if ($mimeType && !$is_dir && $this->preview->isMimeSupported($mimeType) && $exist) {
$tmpl->assign('previewImageLink', $this->urlGenerator->linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150)));
} else {
$mimeTypeIcon = Template::mimetype_icon($is_dir ? 'dir' : $mimeType);
$mimeTypeIcon = substr($mimeTypeIcon, -4) === '.png' ? substr($mimeTypeIcon, 0, -4) . '.svg' : $mimeTypeIcon;
$tmpl->assign('previewImageLink', $mimeTypeIcon);
$tmpl->assign('previewLinkIsDir', true);
}
}
return $tmpl->fetchPage();
}
开发者ID:AARNet,项目名称:activity,代码行数:34,代码来源:display.php
示例5: __construct
public function __construct($params)
{
$host = $params['host'];
//remove leading http[s], will be generated in createBaseUri()
if (substr($host, 0, 8) == "https://") {
$host = substr($host, 8);
} else {
if (substr($host, 0, 7) == "http://") {
$host = substr($host, 7);
}
}
$this->host = $host;
$this->user = $params['user'];
$this->password = $params['password'];
$this->secure = isset($params['secure']) && $params['secure'] == 'true' ? true : false;
$this->root = isset($params['root']) ? $params['root'] : '/';
if (!$this->root || $this->root[0] != '/') {
$this->root = '/' . $this->root;
}
if (substr($this->root, -1, 1) != '/') {
$this->root .= '/';
}
$settings = array('baseUri' => $this->createBaseUri(), 'userName' => $this->user, 'password' => $this->password);
$this->client = new OC_Connector_Sabre_Client($settings);
if ($caview = \OCP\Files::getStorage('files_external')) {
$certPath = \OCP\Config::getSystemValue('datadirectory') . $caview->getAbsolutePath("") . 'rootcerts.crt';
if (file_exists($certPath)) {
$this->client->addTrustedCertificates($certPath);
}
}
//create the root folder if necesary
$this->mkdir('');
}
开发者ID:noci2012,项目名称:owncloud,代码行数:33,代码来源:webdav.php
示例6: searchDocuments
protected static function searchDocuments()
{
$documents = array();
foreach (self::getSupportedMimetypes() as $mime) {
$documents = array_merge($documents, \OCP\Files::searchByMime($mime));
}
return $documents;
}
开发者ID:ozcan,项目名称:richdocuments,代码行数:8,代码来源:storage.php
示例7: hostKeysPath
private function hostKeysPath()
{
try {
$storage_view = \OCP\Files::getStorage('files_external');
if ($storage_view) {
return \OCP\Config::getSystemValue('datadirectory') . $storage_view->getAbsolutePath('') . 'ssh_hostKeys';
}
} catch (\Exception $e) {
}
return false;
}
开发者ID:hjimmy,项目名称:owncloud,代码行数:11,代码来源:sftp.php
示例8: download
public function download($filename)
{
$file = basename($filename);
$filename = $this->config->getBackupBase() . $file;
// Prevent directory traversal
if (strlen($file) < 3 || !@file_exists($filename)) {
exit;
}
$mime = \OCP\Files::getMimeType($filename);
return new DataDownloadResponse(file_get_contents($filename), $file, $mime);
}
开发者ID:FelixHsieh,项目名称:updater,代码行数:11,代码来源:backupcontroller.php
示例9: getDocuments
public static function getDocuments()
{
$list = array_filter(\OCP\Files::searchByMime('application/vnd.oasis.opendocument.text'), function ($item) {
//filter Deleted
if (strpos($item['path'], '_trashbin') === 0) {
return false;
}
return true;
});
return $list;
}
开发者ID:omusico,项目名称:isle-web-framework,代码行数:11,代码来源:storage.php
示例10: convertLocal
/**
* convert via openOffice hosted on the same server
* @param string $input
* @param string $targetFilter
* @param string $targetExtension
* @return string
*/
protected static function convertLocal($input, $targetFilter, $targetExtension)
{
$infile = \OCP\Files::tmpFile();
$outdir = \OCP\Files::tmpFolder();
$cmd = Helper::findOpenOffice();
$params = ' --headless --convert-to ' . $targetFilter . ' --outdir ' . escapeshellarg($outdir) . ' --writer ' . escapeshellarg($infile) . ' -env:UserInstallation=file://' . escapeshellarg(get_temp_dir() . '/owncloud-' . \OC_Util::getInstanceId() . '/');
file_put_contents($infile, $input);
shell_exec($cmd . $params);
$output = file_get_contents($outdir . '/' . basename($infile) . '.' . $targetExtension);
return $output;
}
开发者ID:Ebimedia,项目名称:owncloud,代码行数:18,代码来源:converter.php
示例11: getPresentations
public static function getPresentations()
{
$presentations = array();
$list = \OCP\Files::searchByMime('text/impress');
foreach ($list as $l) {
$size = \OC\Files\Filesystem::filesize($l["path"]);
if ($size > 0) {
$info = pathinfo($l["path"]);
$mtime = \OC\Files\Filesystem::filemtime($l["path"]);
$entry = array('url' => $l["path"], 'name' => $info['filename'], 'size' => $size, 'mtime' => $mtime);
$presentations[] = $entry;
}
}
return $presentations;
}
开发者ID:DOM-Digital-Online-Media,项目名称:apps,代码行数:15,代码来源:impress.php
示例12: update
public static function update($version, $backupBase)
{
if (!is_dir($backupBase)) {
throw new \Exception("Backup directory {$backupBase} is not found");
}
// Switch include paths to backup
$pathsArray = explode(PATH_SEPARATOR, get_include_path());
$pathsTranslated = [];
foreach ($pathsArray as $path) {
//Update all 3rdparty paths
if (preg_match('|^' . preg_quote(\OC::$THIRDPARTYROOT . '/3rdparty') . '|', $path)) {
$pathsTranslated[] = preg_replace('|^' . preg_quote(\OC::$THIRDPARTYROOT . '/3rdparty') . '|', $backupBase . '/3rdparty', $path);
continue;
}
// Update all OC webroot paths
$pathsTranslated[] = preg_replace('|^' . preg_quote(\OC::$SERVERROOT) . '|', $backupBase, $path);
}
set_include_path(implode(PATH_SEPARATOR, $pathsTranslated));
$tempDir = self::getTempDir();
Helper::mkdir($tempDir, true);
$installed = Helper::getDirectories();
$sources = Helper::getSources($version);
try {
$thirdPartyUpdater = new \OCA\Updater\Location\Thirdparty($installed[Helper::THIRDPARTY_DIRNAME], $sources[Helper::THIRDPARTY_DIRNAME]);
$thirdPartyUpdater->update($tempDir . '/' . Helper::THIRDPARTY_DIRNAME);
self::$processed[] = $thirdPartyUpdater;
$coreUpdater = new \OCA\Updater\Location\Core($installed[Helper::CORE_DIRNAME], $sources[Helper::CORE_DIRNAME]);
$coreUpdater->update($tempDir . '/' . Helper::CORE_DIRNAME);
self::$processed[] = $coreUpdater;
$appsUpdater = new \OCA\Updater\Location\Apps('', $sources[Helper::APP_DIRNAME]);
$appsUpdater->update($tempDir . '/' . Helper::APP_DIRNAME);
self::$processed[] = $appsUpdater;
} catch (\Exception $e) {
self::rollBack();
self::cleanUp();
throw $e;
}
// zip backup
$zip = new \ZipArchive();
if ($zip->open($backupBase . ".zip", \ZIPARCHIVE::CREATE) === true) {
Helper::addDirectoryToZip($zip, $backupBase);
$zip->close();
\OCP\Files::rmdirr($backupBase);
}
return true;
}
开发者ID:samj1912,项目名称:repo,代码行数:46,代码来源:updater.php
示例13: rename_hook
/**
* @brief rename/move versions of renamed/moved files
* @param array with oldpath and newpath
*
* This function is connected to the rename signal of OC_Filesystem and adjust the name and location
* of the stored versions along the actual file
*/
public static function rename_hook($params)
{
$versions_fileview = \OCP\Files::getStorage('files_versions');
$rel_oldpath = $params['oldpath'];
$abs_oldpath = \OCP\Config::getSystemValue('datadirectory') . $versions_fileview->getAbsolutePath('') . $rel_oldpath . '.v';
$abs_newpath = \OCP\Config::getSystemValue('datadirectory') . $versions_fileview->getAbsolutePath('') . $params['newpath'] . '.v';
if (Storage::isversioned($rel_oldpath)) {
$info = pathinfo($abs_newpath);
if (!file_exists($info['dirname'])) {
mkdir($info['dirname'], 0750, true);
}
$versions = Storage::getVersions($rel_oldpath);
foreach ($versions as $v) {
rename($abs_oldpath . $v['version'], $abs_newpath . $v['version']);
}
}
}
开发者ID:ryanshoover,项目名称:core,代码行数:24,代码来源:hooks.php
示例14: av_scan
public static function av_scan($path)
{
$path = $path[\OC\Files\Filesystem::signal_param_path];
if ($path != '') {
if (isset($_POST['dirToken'])) {
//Public upload case
$filesView = \OC\Files\Filesystem::getView();
} else {
$filesView = \OCP\Files::getStorage("files");
}
if (!is_object($filesView)) {
\OCP\Util::writeLog('files_antivirus', 'Can\'t init filesystem view', \OCP\Util::WARN);
return;
}
// check if path is a directory
if ($filesView->is_dir($path)) {
return;
}
// we should have a file to work with, and the file shouldn't
// be empty
$fileExists = $filesView->file_exists($path);
if ($fileExists && $filesView->filesize($path) > 0) {
$fileStatus = self::scanFile($filesView, $path);
$result = $fileStatus->getNumericStatus();
switch ($result) {
case Status::SCANRESULT_UNCHECKED:
//TODO: Show warning to the user: The file can not be checked
break;
case Status::SCANRESULT_INFECTED:
//remove file
$filesView->unlink($path);
Notification::sendMail($path);
$message = \OCP\Util::getL10N('files_antivirus')->t("Virus detected! Can't upload the file %s", array(basename($path)));
\OCP\JSON::error(array("data" => array("message" => $message)));
exit;
break;
case Status::SCANRESULT_CLEAN:
//do nothing
break;
}
}
}
}
开发者ID:WYSAC,项目名称:oregon-owncloud,代码行数:43,代码来源:scanner.php
示例15: getPackage
public static function getPackage($url, $version)
{
self::$package = \OCP\Files::tmpFile();
if (!self::$package) {
throw new \Exception('Unable to create a temporary file');
}
try {
if (self::fetch($url) === false) {
throw new \Exception("Error storing package content");
}
if (preg_match('/\\.zip$/i', $url)) {
rename(self::$package, self::$package . '.zip');
self::$package .= '.zip';
} elseif (preg_match('/(\\.tgz|\\.tar\\.gz)$/i', $url)) {
rename(self::$package, self::$package . '.tgz');
self::$package .= '.tgz';
} elseif (preg_match('/\\.tar\\.bz2$/i', $url)) {
rename(self::$package, self::$package . '.tar.bz2');
self::$package .= '.tar.bz2';
} else {
throw new \Exception('Unable to extract package');
}
$extractDir = self::getPackageDir($version);
Helper::mkdir($extractDir, true);
$archive = \OC_Archive::open(self::$package);
if (!$archive || !$archive->extract($extractDir)) {
throw new \Exception(self::$package . " extraction error");
}
} catch (\Exception $e) {
App::log('Retrieving ' . $url);
self::cleanUp($version);
throw $e;
}
Helper::removeIfExists(self::$package);
// Prepare extracted data
// to have '3rdparty', 'apps' and 'core' subdirectories
$sources = Helper::getSources($version);
$baseDir = $extractDir . '/' . self::PACKAGE_ROOT;
rename($baseDir . '/' . Helper::THIRDPARTY_DIRNAME, $sources[Helper::THIRDPARTY_DIRNAME]);
rename($baseDir . '/' . Helper::APP_DIRNAME, $sources[Helper::APP_DIRNAME]);
rename($baseDir, $sources[Helper::CORE_DIRNAME]);
}
开发者ID:CDN-Sparks,项目名称:owncloud,代码行数:42,代码来源:downloader.php
示例16: testConversion
public static function testConversion()
{
$targetFilter = 'odt:writer8';
$targetExtension = 'odt';
$input = file_get_contents(dirname(__DIR__) . self::TEST_DOC_PATH);
$infile = \OCP\Files::tmpFile();
$outdir = \OCP\Files::tmpFolder();
$outfile = $outdir . '/' . basename($infile) . '.' . $targetExtension;
$cmd = Helper::findOpenOffice();
$params = ' --headless --convert-to ' . escapeshellarg($targetFilter) . ' --outdir ' . escapeshellarg($outdir) . ' --writer ' . escapeshellarg($infile) . ' -env:UserInstallation=file://' . escapeshellarg(get_temp_dir() . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' 2>&1';
file_put_contents($infile, $input);
$result = shell_exec($cmd . $params);
$exists = file_exists($outfile);
if (!$exists) {
Helper::warnLog('Conversion test failed. Raw output:' . $result);
return false;
} else {
unlink($outfile);
}
return true;
}
开发者ID:Ebimedia,项目名称:owncloud,代码行数:21,代码来源:config.php
示例17: av_scan
public static function av_scan($path)
{
$path = $path[\OC\Files\Filesystem::signal_param_path];
if ($path != '') {
$files_view = \OCP\Files::getStorage("files");
if ($files_view->file_exists($path)) {
$root = OC_User::getHome(OC_User::getUser()) . '/files';
$file = $root . $path;
$result = self::clamav_scan($file);
switch ($result) {
case CLAMAV_SCANRESULT_UNCHECKED:
//TODO: Show warning to the user: The file can not be checked
break;
case CLAMAV_SCANRESULT_INFECTED:
//remove file
$files_view->unlink($path);
OCP\JSON::error(array("data" => array("message" => "Virus detected! Can't upload the file.")));
$email = OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', '');
\OCP\Util::writeLog('files_antivirus', 'Email: ' . $email, \OCP\Util::DEBUG);
if (!empty($email)) {
$tmpl = new OC_Template('files_antivirus', 'notification');
$tmpl->assign('file', $path);
$tmpl->assign('host', OCP\Util::getServerHost());
$tmpl->assign('user', OC_User::getUser());
$msg = $tmpl->fetchPage();
$from = OCP\Util::getDefaultEmailAddress('security-noreply');
OCP\Util::sendMail($email, OC_User::getUser(), 'Malware detected', $msg, $from, 'ownCloud', 1);
}
exit;
break;
case CLAMAV_SCANRESULT_CLEAN:
//do nothing
break;
}
}
}
}
开发者ID:CDN-Sparks,项目名称:owncloud,代码行数:37,代码来源:clamav.php
示例18: fopen
public function fopen($path, $mode)
{
switch ($mode) {
case 'r':
case 'rb':
case 'w':
case 'wb':
case 'a':
case 'ab':
//these are supported by the wrapper
$context = stream_context_create(array('ftp' => array('overwrite' => true)));
return fopen($this->constructUrl($path), $mode, false, $context);
case 'r+':
case 'w+':
case 'wb+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
//emulate these
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OCP\Files::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$this->getFile($path, $tmpFile);
}
self::$tempFiles[$tmpFile] = $path;
return fopen('close://' . $tmpFile, $mode);
}
return false;
}
开发者ID:CDN-Sparks,项目名称:owncloud,代码行数:36,代码来源:ftp.php
示例19: fopen
/**
* @param string $path
* @param string $mode
* @return resource
*/
public function fopen($path, $mode)
{
$fullPath = $this->buildPath($path);
try {
switch ($mode) {
case 'r':
case 'rb':
if (!$this->file_exists($path)) {
return false;
}
return $this->share->read($fullPath);
case 'w':
case 'wb':
return $this->share->write($fullPath);
case 'a':
case 'ab':
case 'r+':
case 'w+':
case 'wb+':
case 'a+':
case 'x':
case 'x+':
case 'c':
case 'c+':
//emulate these
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
if ($this->file_exists($path)) {
if (!$this->isUpdatable($path)) {
return false;
}
$tmpFile = $this->getCachedFile($path);
} else {
if (!$this->isCreatable(dirname($path))) {
return false;
}
$tmpFile = \OCP\Files::tmpFile($ext);
}
$source = fopen($tmpFile, $mode);
$share = $this->share;
return CallBackWrapper::wrap($source, null, null, function () use($tmpFile, $fullPath, $share) {
$share->put($tmpFile, $fullPath);
unlink($tmpFile);
});
}
return false;
} catch (NotFoundException $e) {
return false;
}
}
开发者ID:evanjt,项目名称:core,代码行数:58,代码来源:smb.php
示例20: toTmpFile
private function toTmpFile($path)
{
$tmpFile = \OCP\Files::tmpFile();
$this->archive->extractFile($path, $tmpFile);
return $tmpFile;
}
开发者ID:anolisti,项目名称:apps,代码行数:6,代码来源:storage.php
注:本文中的OCP\Files类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论