本文整理汇总了PHP中elFinder类的典型用法代码示例。如果您正苦于以下问题:PHP elFinder类的具体用法?PHP elFinder怎么用?PHP elFinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了elFinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _save
/**
* Create new file and write into it from file pointer.
* Return new file path or false on error.
*
* @param resource $fp file pointer
* @param string $dir target dir path
* @param string $name file name
* @param array $stat file stat (required by some virtual fs)
*
* @return bool|string
*
* @author Dmitry (dio) Levashov
**/
protected function _save($fp, $path, $name, $stat)
{
if ($name !== '') {
$path .= '/' . $name;
}
list($parentId, $itemId, $parent) = $this->_gd_splitPath($path);
if ($name === '') {
$stat['iid'] = $itemId;
}
if (!$stat || empty($stat['iid'])) {
$opts = ['q' => sprintf('trashed=false and "%s" in parents and name="%s"', $parentId, $name), 'fields' => self::FETCHFIELDS_LIST];
$srcFile = $this->_gd_query($opts);
$srcFile = empty($srcFile) ? null : $srcFile[0];
} else {
$srcFile = $this->_gd_getFile($path);
}
try {
$mode = 'update';
$mime = isset($stat['mime']) ? $stat['mime'] : '';
$file = new Google_Service_Drive_DriveFile();
if ($srcFile) {
$mime = $srcFile->getMimeType();
} else {
$mode = 'insert';
$file->setName($name);
$file->setParents([$parentId]);
}
if (!$mime) {
$mime = self::mimetypeInternalDetect($name);
}
if ($mime === 'unknown') {
$mime = 'application/octet-stream';
}
$file->setMimeType($mime);
$size = 0;
if (isset($stat['size'])) {
$size = $stat['size'];
} else {
$fstat = fstat($fp);
if (!empty($fstat['size'])) {
$size = $fstat['size'];
}
}
// set chunk size (max: 100MB)
$chunkSizeBytes = 100 * 1024 * 1024;
if ($size > 0) {
$memory = elFinder::getIniBytes('memory_limit');
if ($memory) {
$chunkSizeBytes = min([$chunkSizeBytes, intval($memory / 4 / 256) * 256]);
}
}
if ($size > $chunkSizeBytes) {
$client = $this->client;
// Call the API with the media upload, defer so it doesn't immediately return.
$client->setDefer(true);
if ($mode === 'insert') {
$request = $this->service->files->create($file, ['fields' => self::FETCHFIELDS_GET]);
} else {
$request = $this->service->files->update($srcFile->getId(), $file, ['fields' => self::FETCHFIELDS_GET]);
}
// Create a media file upload to represent our upload process.
$media = new Google_Http_MediaFileUpload($client, $request, $mime, null, true, $chunkSizeBytes);
$media->setFileSize($size);
// Upload the various chunks. $status will be false until the process is
// complete.
$status = false;
while (!$status && !feof($fp)) {
elFinder::extendTimeLimit();
// read until you get $chunkSizeBytes from TESTFILE
// fread will never return more than 8192 bytes if the stream is read buffered and it does not represent a plain file
// An example of a read buffered file is when reading from a URL
$chunk = $this->_gd_readFileChunk($fp, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
// The final value of $status will be the data from the API for the object
// that has been uploaded.
if ($status !== false) {
$obj = $status;
}
$client->setDefer(false);
} else {
$params = ['data' => stream_get_contents($fp), 'uploadType' => 'media', 'fields' => self::FETCHFIELDS_GET];
if ($mode === 'insert') {
$obj = $this->service->files->create($file, $params);
} else {
$obj = $this->service->files->update($srcFile->getId(), $file, $params);
}
//.........这里部分代码省略.........
示例2: log
/**
* Create log record
*
* @param string $cmd command name
* @param array $result command result
* @param array $args command arguments from client
* @param elFinder $elfinder elFinder instance
* @return void|true
* @author Dmitry (dio) Levashov
**/
public function log($cmd, $result, $args, $elfinder)
{
$log = $cmd . ' [' . date('d.m H:s') . "]\n";
if (!empty($result['error'])) {
$log .= "\tERROR: " . implode(' ', $result['error']) . "\n";
}
if (!empty($result['warning'])) {
$log .= "\tWARNING: " . implode(' ', $result['warning']) . "\n";
}
if (!empty($result['removed'])) {
foreach ($result['removed'] as $file) {
// removed file contain additional field "realpath"
$log .= "\tREMOVED: " . $file['realpath'] . "\n";
//preg_match('/[^\/]+$/', $file['realpath'], $file);
//$log .= $file[0];
}
}
if (!empty($result['added'])) {
foreach ($result['added'] as $file) {
$log .= "\tADDED: " . $elfinder->realpath($file['hash']) . "\n";
}
}
if (!empty($result['changed'])) {
foreach ($result['changed'] as $file) {
$log .= "\tCHANGED: " . $elfinder->realpath($file['hash']) . "\n";
}
}
$this->write($log);
}
示例3: run
/**
* Execute elFinder command and output result
*
* @return void
* @author Dmitry (dio) Levashov
**/
public function run()
{
$isPost = $_SERVER["REQUEST_METHOD"] == 'POST';
$src = $_SERVER["REQUEST_METHOD"] == 'POST' ? $_POST : $_GET;
$cmd = isset($src['cmd']) ? $src['cmd'] : '';
$args = array();
if (!function_exists('json_encode')) {
$error = $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_JSON);
$this->output(array('error' => '{"error":["' . implode('","', $error) . '"]}', 'raw' => true));
}
if (!$this->elFinder->loaded()) {
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_VOL)));
}
// telepat_mode: on
if (!$cmd && $isPost) {
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UPLOAD_COMMON, elFinder::ERROR_UPLOAD_FILES_SIZE), 'header' => 'Content-Type: text/html'));
}
// telepat_mode: off
if (!$this->elFinder->commandExists($cmd)) {
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UNKNOWN_CMD)));
}
// collect required arguments to exec command
foreach ($this->elFinder->commandArgsList($cmd) as $name => $req) {
$arg = $name == 'FILES' ? $_FILES : (isset($src[$name]) ? $src[$name] : '');
if (!is_array($arg)) {
$arg = trim($arg);
}
if ($req && empty($arg)) {
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_INV_PARAMS, $cmd)));
}
$args[$name] = $arg;
}
$args['debug'] = isset($src['debug']) ? !!$src['debug'] : false;
$this->output($this->elFinder->exec($cmd, $args));
}
示例4: actionConnector
public function actionConnector()
{
$this->layout = false;
Yii::import('elfinder.vendors.*');
require_once 'elFinder.class.php';
$opts = array('root' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR, 'URL' => Yii::app()->baseUrl . '/upload/', 'rootAlias' => 'Home');
$fm = new elFinder($opts);
$fm->run();
}
示例5: connector
public function connector()
{
$this->show->Title = 'Менеджер файлов';
include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'elFinder.class.php';
// $log = new elFinderLogger();
$opts = array('root' => DOC_ROOT . 'var/custom', 'URL' => BASE_PATH . 'var/custom/', 'rootAlias' => $this->show->Title);
$fm = new elFinder($opts);
$fm->run();
}
示例6: execute
/**
* Execute elFinder command and returns result
* @param array $queryParameters GET query parameters.
* @return array
* @author Dmitry (dio) Levashov
**/
public function execute($queryParameters)
{
$isPost = $_SERVER["REQUEST_METHOD"] == 'POST';
$src = $_SERVER["REQUEST_METHOD"] == 'POST' ? array_merge($_POST, $queryParameters) : $queryParameters;
if ($isPost && !$src && ($rawPostData = @file_get_contents('php://input'))) {
// for support IE XDomainRequest()
$parts = explode('&', $rawPostData);
foreach ($parts as $part) {
list($key, $value) = array_pad(explode('=', $part), 2, '');
$src[$key] = rawurldecode($value);
}
$_POST = $src;
$_REQUEST = array_merge_recursive($src, $_REQUEST);
}
$cmd = isset($src['cmd']) ? $src['cmd'] : '';
$args = array();
if (!function_exists('json_encode')) {
$error = $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_JSON);
return $this->output(array('error' => '{"error":["' . implode('","', $error) . '"]}', 'raw' => true));
}
if (!$this->elFinder->loaded()) {
return $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_VOL), 'debug' => $this->elFinder->mountErrors));
}
// telepat_mode: on
if (!$cmd && $isPost) {
return $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UPLOAD, elFinder::ERROR_UPLOAD_TOTAL_SIZE), 'header' => 'Content-Type: text/html'));
}
// telepat_mode: off
if (!$this->elFinder->commandExists($cmd)) {
return $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UNKNOWN_CMD)));
}
// collect required arguments to exec command
foreach ($this->elFinder->commandArgsList($cmd) as $name => $req) {
$arg = $name == 'FILES' ? $_FILES : (isset($src[$name]) ? $src[$name] : '');
if (!is_array($arg)) {
$arg = trim($arg);
}
if ($req && (!isset($arg) || $arg === '')) {
return $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_INV_PARAMS, $cmd)));
}
$args[$name] = $arg;
}
$args['debug'] = isset($src['debug']) ? !!$src['debug'] : false;
return $this->output($this->elFinder->exec($cmd, $this->input_filter($args)));
}
示例7: onUpLoadPreSave
public function onUpLoadPreSave(&$path, &$name, $src, $elfinder, $volume)
{
$opts = $this->opts;
$volOpts = $volume->getOptionsPlugin('Watermark');
if (is_array($volOpts)) {
$opts = array_merge($this->opts, $volOpts);
}
if (!$opts['enable']) {
return false;
}
$srcImgInfo = @getimagesize($src);
if ($srcImgInfo === false) {
return false;
}
// check Animation Gif
if (elFinder::isAnimationGif($src)) {
return false;
}
// check water mark image
if (!file_exists($opts['source'])) {
$opts['source'] = dirname(__FILE__) . "/" . $opts['source'];
}
if (is_readable($opts['source'])) {
$watermarkImgInfo = @getimagesize($opts['source']);
if (!$watermarkImgInfo) {
return false;
}
} else {
return false;
}
$watermark = $opts['source'];
$marginLeft = $opts['marginRight'];
$marginBottom = $opts['marginBottom'];
$quality = $opts['quality'];
$transparency = $opts['transparency'];
// check target image type
$imgTypes = array(IMAGETYPE_GIF => IMG_GIF, IMAGETYPE_JPEG => IMG_JPEG, IMAGETYPE_PNG => IMG_PNG, IMAGETYPE_WBMP => IMG_WBMP);
if (!($opts['targetType'] & $imgTypes[$srcImgInfo[2]])) {
return false;
}
// check target image size
if ($opts['targetMinPixel'] > 0 && $opts['targetMinPixel'] > min($srcImgInfo[0], $srcImgInfo[1])) {
return false;
}
$watermark_width = $watermarkImgInfo[0];
$watermark_height = $watermarkImgInfo[1];
$dest_x = $srcImgInfo[0] - $watermark_width - $marginLeft;
$dest_y = $srcImgInfo[1] - $watermark_height - $marginBottom;
if (class_exists('Imagick')) {
return $this->watermarkPrint_imagick($src, $watermark, $dest_x, $dest_y, $quality, $transparency, $watermarkImgInfo);
} else {
return $this->watermarkPrint_gd($src, $watermark, $dest_x, $dest_y, $quality, $transparency, $watermarkImgInfo, $srcImgInfo);
}
}
示例8: configure
protected function configure()
{
parent::configure();
$this->tmpPath = '';
if (!empty($this->options['tmpPath'])) {
if ((is_dir($this->options['tmpPath']) || @mkdir($this->options['tmpPath'])) && is_writable($this->options['tmpPath'])) {
$this->tmpPath = $this->options['tmpPath'];
}
}
if (!$this->tmpPath && ($tmp = elFinder::getStaticVar('commonTempPath'))) {
$this->tmpPath = $tmp;
}
$this->mimeDetect = 'internal';
}
示例9: __construct
/**
* Constructor
*
* @param array elFinder and roots configurations
* @return void
* @author nao-pon
**/
public function __construct($opts)
{
parent::__construct($opts);
$this->commands['perm'] = array('target' => true, 'perm' => true, 'umask' => false, 'gids' => false, 'filter' => false);
}
示例10: localFileSystemInotify
/**
* Long pooling sync checker
* This function require server command `inotifywait`
* If `inotifywait` need full path, Please add `define('ELFINER_INOTIFYWAIT_PATH', '/PATH_TO/inotifywait');` into connector.php
*
* @param string $path
* @param int $standby
* @param number $compare
* @return number|bool
*/
public function localFileSystemInotify($path, $standby, $compare)
{
if (isset($this->sessionCache['localFileSystemInotify_disable'])) {
return false;
}
$path = realpath($path);
$mtime = filemtime($path);
if ($mtime != $compare) {
return $mtime;
}
$inotifywait = defined('ELFINER_INOTIFYWAIT_PATH') ? ELFINER_INOTIFYWAIT_PATH : 'inotifywait';
$path = escapeshellarg($path);
$standby = max(1, intval($standby));
$cmd = $inotifywait . ' ' . $path . ' -t ' . $standby . ' -e moved_to,moved_from,move,close_write,delete,delete_self';
$this->procExec($cmd, $o, $r);
if ($r === 0) {
// changed
clearstatcache();
$mtime = @filemtime($path);
// error on busy?
return $mtime ? $mtime : time();
} else {
if ($r === 2) {
// not changed (timeout)
return $compare;
}
}
// error
// cache to $_SESSION
$sessionStart = $this->sessionRestart();
if ($sessionStart) {
$this->sessionCache['localFileSystemInotify_disable'] = true;
elFinder::sessionWrite();
}
return false;
}
示例11: __construct
/**
* Constructor
*
* @param array elFinder and roots configurations
* @return void
* @author Dmitry (dio) Levashov
**/
public function __construct($opts)
{
if (session_id() == '') {
session_start();
}
$this->time = $this->utime();
$this->debug = isset($opts['debug']) && $opts['debug'] ? true : false;
$this->timeout = isset($opts['timeout']) ? $opts['timeout'] : 0;
$this->netVolumesSessionKey = !empty($opts['netVolumesSessionKey']) ? $opts['netVolumesSessionKey'] : 'elFinderNetVolumes';
$this->callbackWindowURL = isset($opts['callbackWindowURL']) ? $opts['callbackWindowURL'] : '';
self::$sessionCacheKey = !empty($opts['sessionCacheKey']) ? $opts['sessionCacheKey'] : 'elFinderCaches';
// check session cache
$_optsMD5 = md5(json_encode($opts['roots']));
if (!isset($_SESSION[self::$sessionCacheKey]) || $_SESSION[self::$sessionCacheKey]['_optsMD5'] !== $_optsMD5) {
$_SESSION[self::$sessionCacheKey] = array('_optsMD5' => $_optsMD5);
}
// setlocale and global locale regists to elFinder::locale
self::$locale = !empty($opts['locale']) ? $opts['locale'] : 'en_US.UTF-8';
if (false === @setlocale(LC_ALL, self::$locale)) {
self::$locale = setlocale(LC_ALL, '');
}
// bind events listeners
if (!empty($opts['bind']) && is_array($opts['bind'])) {
$_req = $_SERVER["REQUEST_METHOD"] == 'POST' ? $_POST : $_GET;
$_reqCmd = isset($_req['cmd']) ? $_req['cmd'] : '';
foreach ($opts['bind'] as $cmd => $handlers) {
$doRegist = strpos($cmd, '*') !== false;
if (!$doRegist) {
$_getcmd = create_function('$cmd', 'list($ret) = explode(\'.\', $cmd);return trim($ret);');
$doRegist = $_reqCmd && in_array($_reqCmd, array_map($_getcmd, explode(' ', $cmd)));
}
if ($doRegist) {
if (!is_array($handlers) || is_object($handlers[0])) {
$handlers = array($handlers);
}
foreach ($handlers as $handler) {
if ($handler) {
if (is_string($handler) && strpos($handler, '.')) {
list($_domain, $_name, $_method) = array_pad(explode('.', $handler), 3, '');
if (strcasecmp($_domain, 'plugin') === 0) {
if ($plugin = $this->getPluginInstance($_name, isset($opts['plugin'][$_name]) ? $opts['plugin'][$_name] : array()) and method_exists($plugin, $_method)) {
$this->bind($cmd, array($plugin, $_method));
}
}
} else {
$this->bind($cmd, $handler);
}
}
}
}
}
}
if (!isset($opts['roots']) || !is_array($opts['roots'])) {
$opts['roots'] = array();
}
// check for net volumes stored in session
foreach ($this->getNetVolumes() as $root) {
$opts['roots'][] = $root;
}
// "mount" volumes
foreach ($opts['roots'] as $i => $o) {
$class = 'elFinderVolume' . (isset($o['driver']) ? $o['driver'] : '');
if (class_exists($class)) {
$volume = new $class();
try {
if ($volume->mount($o)) {
// unique volume id (ends on "_") - used as prefix to files hash
$id = $volume->id();
$this->volumes[$id] = $volume;
if (!$this->default && $volume->isReadable()) {
$this->default = $this->volumes[$id];
}
} else {
$this->removeNetVolume($volume);
$this->mountErrors[] = 'Driver "' . $class . '" : ' . implode(' ', $volume->error());
}
} catch (Exception $e) {
$this->removeNetVolume($volume);
$this->mountErrors[] = 'Driver "' . $class . '" : ' . $e->getMessage();
}
} else {
$this->mountErrors[] = 'Driver "' . $class . '" does not exists';
}
}
// if at least one readable volume - ii desu >_<
$this->loaded = !empty($this->default);
}
示例12: output
/**
* Output json
*
* @param array data to output
* @return void
* @author Dmitry (dio) Levashov
**/
protected function output(array $data)
{
// clear output buffer
while (@ob_get_level()) {
@ob_end_clean();
}
$header = isset($data['header']) ? $data['header'] : $this->header;
unset($data['header']);
if ($header) {
if (is_array($header)) {
foreach ($header as $h) {
header($h);
}
} else {
header($header);
}
}
if (isset($data['pointer'])) {
$toEnd = true;
$fp = $data['pointer'];
if (elFinder::isSeekableStream($fp)) {
header('Accept-Ranges: bytes');
$psize = null;
if (!empty($_SERVER['HTTP_RANGE'])) {
$size = $data['info']['size'];
$start = 0;
$end = $size - 1;
if (preg_match('/bytes=(\\d*)-(\\d*)(,?)/i', $_SERVER['HTTP_RANGE'], $matches)) {
if (empty($matches[3])) {
if (empty($matches[1]) && $matches[1] !== '0') {
$start = $size - $matches[2];
} else {
$start = intval($matches[1]);
if (!empty($matches[2])) {
$end = intval($matches[2]);
if ($end >= $size) {
$end = $size - 1;
}
$toEnd = $end == $size - 1;
}
}
$psize = $end - $start + 1;
header('HTTP/1.1 206 Partial Content');
header('Content-Length: ' . $psize);
header('Content-Range: bytes ' . $start . '-' . $end . '/' . $size);
fseek($fp, $start);
}
}
}
if (is_null($psize)) {
rewind($fp);
}
} else {
header('Accept-Ranges: none');
}
// unlock session data for multiple access
session_id() && session_write_close();
// client disconnect should abort
ignore_user_abort(false);
if ($toEnd) {
fpassthru($fp);
} else {
$out = fopen('php://output', 'wb');
stream_copy_to_stream($fp, $out, $psize);
fclose($out);
}
if (!empty($data['volume'])) {
$data['volume']->close($data['pointer'], $data['info']['hash']);
}
exit;
} else {
if (!empty($data['raw']) && !empty($data['error'])) {
exit($data['error']);
} else {
exit(json_encode($data));
}
}
}
示例13: configure
/**
* Configure after successfull mount.
*
* @return void
* @author Dmitry (dio) Levashov
**/
protected function configure()
{
parent::configure();
if (!empty($this->options['tmpPath'])) {
if ((is_dir($this->options['tmpPath']) || @mkdir($this->options['tmpPath'], 0755, true)) && is_writable($this->options['tmpPath'])) {
$this->tmp = $this->options['tmpPath'];
}
}
if (!$this->tmp && ($tmp = elFinder::getStaticVar('commonTempPath'))) {
$this->tmp = $tmp;
}
if (!$this->tmp && $this->tmbPath) {
$this->tmp = $this->tmbPath;
}
if (!$this->tmp) {
$this->disabled[] = 'mkfile';
$this->disabled[] = 'paste';
$this->disabled[] = 'duplicate';
$this->disabled[] = 'upload';
$this->disabled[] = 'edit';
$this->disabled[] = 'archive';
$this->disabled[] = 'extract';
}
// echo $this->tmp;
}
示例14:
?>
<?php
echo $form->field($model, 'title')->textInput(['maxlength' => true]);
?>
<?php
echo $form->field($model, 'slug')->textInput(['maxlength' => true]);
?>
<?php
echo $form->field($model, 'image')->widget(InputFile::className(), ['language' => 'en', 'controller' => 'elfinder', 'path' => 'image', 'filter' => 'image', 'template' => '<div class="input-group">{input}<span class="input-group-btn">{button}</span></div>', 'options' => ['class' => 'form-control'], 'buttonOptions' => ['class' => 'btn btn-success'], 'multiple' => false]);
?>
<?php
echo $form->field($model, 'content')->widget(CKEditor::className(), ['editorOptions' => elFinder::ckeditorOptions(['elfinder'], ['preset' => 'standard', 'entities' => false])]);
?>
<?php
echo $form->field($model, 'meta_title')->textInput();
?>
<?php
echo $form->field($model, 'meta_keywords')->textInput(['maxlength' => true]);
?>
<?php
echo $form->field($model, 'meta_description')->textInput(['maxlength' => true]);
?>
<?php
示例15: clearcache
/**
* Clean cache
*
* @return void
* @author Dmitry (dio) Levashov
**/
protected function clearcache()
{
$this->cache = $this->dirsCache = array();
$this->sessionRestart();
unset($this->sessionCache['rootstat'][md5($this->root)]);
elFinder::sessionWrite();
}