本文整理汇总了PHP中OC\Files\Filesystem::fopen方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::fopen方法的具体用法?PHP Filesystem::fopen怎么用?PHP Filesystem::fopen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\Filesystem
的用法示例。
在下文中一共展示了Filesystem::fopen方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addDirRecursive
/**
* Stream directory recursively
* @param string $dir
* @param string $internalDir
*/
public function addDirRecursive($dir, $internalDir = '')
{
$dirname = basename($dir);
$rootDir = $internalDir . $dirname;
if (!empty($rootDir)) {
$this->streamerInstance->addEmptyDir($rootDir);
}
$internalDir .= $dirname . '/';
// prevent absolute dirs
$internalDir = ltrim($internalDir, '/');
$files = \OC\Files\Filesystem::getDirectoryContent($dir);
foreach ($files as $file) {
$filename = $file['name'];
$file = $dir . '/' . $filename;
if (\OC\Files\Filesystem::is_file($file)) {
$filesize = \OC\Files\Filesystem::filesize($file);
$fh = \OC\Files\Filesystem::fopen($file, 'r');
$this->addFileFromStream($fh, $internalDir . $filename, $filesize);
fclose($fh);
} elseif (\OC\Files\Filesystem::is_dir($file)) {
$this->addDirRecursive($file, $internalDir);
}
}
}
示例2: zipAddDir
/**
* @param string $dir
* @param ZipStreamer $zip
* @param string $internalDir
*/
public static function zipAddDir($dir, ZipStreamer $zip, $internalDir = '')
{
$dirname = basename($dir);
$rootDir = $internalDir . $dirname;
if (!empty($rootDir)) {
$zip->addEmptyDir($rootDir);
}
$internalDir .= $dirname .= '/';
// prevent absolute dirs
$internalDir = ltrim($internalDir, '/');
$files = \OC\Files\Filesystem::getDirectoryContent($dir);
foreach ($files as $file) {
$filename = $file['name'];
$file = $dir . '/' . $filename;
if (\OC\Files\Filesystem::is_file($file)) {
$fh = \OC\Files\Filesystem::fopen($file, 'r');
$zip->addFileFromStream($fh, $internalDir . $filename);
fclose($fh);
} elseif (\OC\Files\Filesystem::is_dir($file)) {
self::zipAddDir($file, $zip, $internalDir);
}
}
}
示例3: file_assemble
public function file_assemble($path)
{
$absolutePath = \OC\Files\Filesystem::normalizePath(\OC\Files\Filesystem::getView()->getAbsolutePath($path));
$data = '';
// use file_put_contents as method because that best matches what this function does
if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) && \OC\Files\Filesystem::isValidPath($path)) {
$path = \OC\Files\Filesystem::getView()->getRelativePath($absolutePath);
$exists = \OC\Files\Filesystem::file_exists($path);
$run = true;
if (!$exists) {
OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create, array(\OC\Files\Filesystem::signal_param_path => $path, \OC\Files\Filesystem::signal_param_run => &$run));
}
OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_write, array(\OC\Files\Filesystem::signal_param_path => $path, \OC\Files\Filesystem::signal_param_run => &$run));
if (!$run) {
return false;
}
$target = \OC\Files\Filesystem::fopen($path, 'w');
if ($target) {
$count = $this->assemble($target);
fclose($target);
if (!$exists) {
OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, array(\OC\Files\Filesystem::signal_param_path => $path));
}
OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_write, array(\OC\Files\Filesystem::signal_param_path => $path));
OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
return $count > 0;
} else {
return false;
}
}
}
示例4: get
/**
* return the content of a file or return a zip file containing multiple files
*
* @param string $dir
* @param string $files ; separated list of files to download
* @param boolean $onlyHeader ; boolean to only send header of the request
*/
public static function get($dir, $files, $onlyHeader = false)
{
$view = \OC\Files\Filesystem::getView();
$getType = self::FILE;
$filename = $dir;
try {
if (is_array($files) && count($files) === 1) {
$files = $files[0];
}
if (!is_array($files)) {
$filename = $dir . '/' . $files;
if (!$view->is_dir($filename)) {
self::getSingleFile($view, $dir, $files, $onlyHeader);
return;
}
}
$name = 'download';
if (is_array($files)) {
$getType = self::ZIP_FILES;
$basename = basename($dir);
if ($basename) {
$name = $basename;
}
$filename = $dir . '/' . $name;
} else {
$filename = $dir . '/' . $files;
$getType = self::ZIP_DIR;
// downloading root ?
if ($files !== '') {
$name = $files;
}
}
$streamer = new Streamer();
OC_Util::obEnd();
self::lockFiles($view, $dir, $files);
$streamer->sendHeaders($name);
$executionTime = intval(OC::$server->getIniWrapper()->getNumeric('max_execution_time'));
set_time_limit(0);
if ($getType === self::ZIP_FILES) {
foreach ($files as $file) {
$file = $dir . '/' . $file;
if (\OC\Files\Filesystem::is_file($file)) {
$fileSize = \OC\Files\Filesystem::filesize($file);
$fh = \OC\Files\Filesystem::fopen($file, 'r');
$streamer->addFileFromStream($fh, basename($file), $fileSize);
fclose($fh);
} elseif (\OC\Files\Filesystem::is_dir($file)) {
$streamer->addDirRecursive($file);
}
}
} elseif ($getType === self::ZIP_DIR) {
$file = $dir . '/' . $files;
$streamer->addDirRecursive($file);
}
$streamer->finalize();
set_time_limit($executionTime);
self::unlockAllTheFiles($dir, $files, $getType, $view, $filename);
} catch (\OCP\Lock\LockedException $ex) {
self::unlockAllTheFiles($dir, $files, $getType, $view, $filename);
OC::$server->getLogger()->logException($ex);
$l = \OC::$server->getL10N('core');
$hint = method_exists($ex, 'getHint') ? $ex->getHint() : '';
\OC_Template::printErrorPage($l->t('File is currently busy, please try again later'), $hint);
} catch (\OCP\Files\ForbiddenException $ex) {
self::unlockAllTheFiles($dir, $files, $getType, $view, $filename);
OC::$server->getLogger()->logException($ex);
$l = \OC::$server->getL10N('core');
\OC_Template::printErrorPage($l->t('Can\'t read file'), $ex->getMessage());
} catch (\Exception $ex) {
self::unlockAllTheFiles($dir, $files, $getType, $view, $filename);
OC::$server->getLogger()->logException($ex);
$l = \OC::$server->getL10N('core');
$hint = method_exists($ex, 'getHint') ? $ex->getHint() : '';
\OC_Template::printErrorPage($l->t('Can\'t read file'), $hint);
}
}
示例5: get
/**
* Returns the data
*
* @return string
*/
public function get()
{
//throw exception if encryption is disabled but files are still encrypted
if (\OC_Util::encryptedFiles()) {
throw new \Sabre_DAV_Exception_ServiceUnavailable();
} else {
return \OC\Files\Filesystem::fopen($this->path, 'rb');
}
}
示例6: openFile
public static function openFile($name)
{
if (\OC\Files\Filesystem::isReadable($name)) {
$f = \OC\Files\Filesystem::fopen($name, 'rb');
if ($f !== FALSE) {
return new RessourceReader($f);
}
}
return null;
}
示例7: sprintf
<?php
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
OCP\JSON::checkAppEnabled('files_irods');
$source = $_GET['source'];
$f = \OC\Files\Filesystem::fopen($source, 'r');
$meta = stream_get_meta_data($f)['wrapper_data']->metadata;
$html = "<table id='metadata'>\n <thead>\n <tr>\n <th>Key</th>\n <th>Value</th>\n <th>Units</th>\n <th>Actions</th>\n </tr>\n </thead>\n <tbody>";
foreach ($meta as $m) {
$html .= sprintf("<tr><td class='editable' data-name='name' data-pk={$m->id}>%s</td>\n <td class='editable' data-name='value' data-pk={$m->id}>%s</td>\n <td class='editable' data-name='units' data-pk={$m->id}>%s</td>\n <td><button class='btn btn-danger remove-metadata' data-pk={$m->id}><i class='glyphicon glyphicon-remove'></i> Remove</button></td>\n </tr>", $m->name, $m->value, $m->units);
}
$html .= "</tbody></table>";
\OCP\JSON::success(array('data' => $html));
示例8: header
header('WWW-Authenticate: Basic realm="ownCloud Server"');
header('HTTP/1.0 401 Unauthorized');
echo 'Valid credentials must be supplied';
exit;
} else {
if (!OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) {
exit;
}
}
}
list($type, $file) = explode('/', substr($path_info, 1 + strlen($service) + 1), 2);
if ($type != 'oc_chunked') {
OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
die;
}
if (!\OC\Files\Filesystem::is_file($file)) {
OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
die;
}
switch ($_SERVER['REQUEST_METHOD']) {
case 'PUT':
$input = fopen("php://input", "r");
$org_file = \OC\Files\Filesystem::fopen($file, 'rb');
$info = array('name' => basename($file));
$sync = new OC_FileChunking($info);
$result = $sync->signature_split($org_file, $input);
echo json_encode($result);
break;
default:
OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
}
示例9: fopen
/**
* @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
*/
public static function fopen($path, $mode)
{
return \OC\Files\Filesystem::fopen($path, $mode);
}
示例10: get
/**
* return the content of a file or return a zip file containing multiple files
*
* @param string $dir
* @param string $files ; separated list of files to download
* @param boolean $onlyHeader ; boolean to only send header of the request
*/
public static function get($dir, $files, $onlyHeader = false)
{
$view = \OC\Files\Filesystem::getView();
if (is_array($files) && count($files) === 1) {
$files = $files[0];
}
if (is_array($files)) {
$getType = self::ZIP_FILES;
$basename = basename($dir);
if ($basename) {
$name = $basename;
} else {
$name = 'download';
}
$filename = $dir . '/' . $name;
} else {
$filename = $dir . '/' . $files;
if (\OC\Files\Filesystem::is_dir($dir . '/' . $files)) {
$getType = self::ZIP_DIR;
// downloading root ?
if ($files === '') {
$name = 'download';
} else {
$name = $files;
}
} else {
$getType = self::FILE;
$name = $files;
}
}
if ($getType === self::FILE) {
$streamer = false;
} else {
$streamer = new Streamer();
}
OC_Util::obEnd();
try {
if ($getType === self::FILE) {
$view->lockFile($filename, ILockingProvider::LOCK_SHARED);
}
if ($streamer) {
$streamer->sendHeaders($name);
} elseif (\OC\Files\Filesystem::isReadable($filename)) {
self::sendHeaders($filename, $name);
} elseif (!\OC\Files\Filesystem::file_exists($filename)) {
header("HTTP/1.0 404 Not Found");
$tmpl = new OC_Template('', '404', 'guest');
$tmpl->printPage();
exit;
} else {
header("HTTP/1.0 403 Forbidden");
die('403 Forbidden');
}
if ($onlyHeader) {
return;
}
if ($streamer) {
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
if ($getType === self::ZIP_FILES) {
foreach ($files as $file) {
$file = $dir . '/' . $file;
if (\OC\Files\Filesystem::is_file($file)) {
$fileSize = \OC\Files\Filesystem::filesize($file);
$fh = \OC\Files\Filesystem::fopen($file, 'r');
$streamer->addFileFromStream($fh, basename($file), $fileSize);
fclose($fh);
} elseif (\OC\Files\Filesystem::is_dir($file)) {
$streamer->addDirRecursive($file);
}
}
} elseif ($getType === self::ZIP_DIR) {
$file = $dir . '/' . $files;
$streamer->addDirRecursive($file);
}
$streamer->finalize();
set_time_limit($executionTime);
} else {
\OC\Files\Filesystem::readfile($filename);
}
if ($getType === self::FILE) {
$view->unlockFile($filename, ILockingProvider::LOCK_SHARED);
}
} catch (\OCP\Lock\LockedException $ex) {
$l = \OC::$server->getL10N('core');
$hint = method_exists($ex, 'getHint') ? $ex->getHint() : '';
\OC_Template::printErrorPage($l->t('File is currently busy, please try again later'), $hint);
} catch (\Exception $ex) {
$l = \OC::$server->getL10N('core');
$hint = method_exists($ex, 'getHint') ? $ex->getHint() : '';
\OC_Template::printErrorPage($l->t('Can\'t read file'), $hint);
}
}
示例11: get
/**
* Returns the data
*
* @return string
*/
public function get()
{
return \OC\Files\Filesystem::fopen($this->path, 'rb');
}
示例12:
<?php
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
OCP\JSON::checkAppEnabled('files_irods');
$source = $_POST['source'];
if (isset($_POST['delete'])) {
$f = \OC\Files\Filesystem::fopen("{$source}?id={$_POST['pk']}", 'm-');
if ($f == false) {
\OCP\JSON::error();
} else {
\OCP\JSON::success();
}
return;
}
$f = \OC\Files\Filesystem::fopen("{$source}?name={$_POST['name']}&value={$_POST['value']}&id={$_POST['pk']}", 'm');
$meta = stream_get_meta_data($f)['wrapper_data']->metadata;
$newId = 0;
foreach ($meta as $m) {
if ($m->id > $newId) {
$newId = $m->id;
}
}
if ($f == false) {
\OCP\JSON::error();
} else {
\OCP\JSON::success(array("oldId" => $_POST['pk'], "newId" => $newId));
}