protected function _stat($path)
{
$outPath = $this->convEncOut($path);
if (isset($this->cache[$outPath])) {
return $this->convEncIn($this->cache[$outPath]);
} else {
$this->convEncIn();
}
if (!$this->MLSTsupprt) {
if ($path === $this->root) {
$res = array('name' => $this->root, 'mime' => 'directory', 'dirs' => $this->_subdirs($path));
if ($this->isMyReload()) {
$ts = 0;
foreach (ftp_rawlist($this->connect, $path) as $str) {
if ($stat = $this->parseRaw($str, $path)) {
$ts = max($ts, $stat['ts']);
}
}
if ($ts) {
$res['ts'] = $ts;
}
}
return $res;
}
// stat of system root
if ($path === $this->separator) {
$res = array('name' => $this->separator, 'mime' => 'directory', 'dirs' => 1);
$this->cache[$outPath] = $res;
return $res;
}
$parentSubdirs = null;
$outParent = $this->convEncOut($this->_dirname($path));
if (isset($this->sessionCache['subdirs']) && isset($this->sessionCache['subdirs'][$outParent])) {
$parentSubdirs = $this->sessionCache['subdirs'][$outParent];
}
$this->cacheDir($outParent);
if ($parentSubdirs) {
$this->sessionCache['subdirs'][$outParent] = $parentSubdirs;
}
$stat = $this->convEncIn(isset($this->cache[$outPath]) ? $this->cache[$outPath] : array());
if (!$this->mounted) {
// dispose incomplete cache made by calling `stat` by 'startPath' option
$this->cache = array();
}
return $stat;
}
$raw = ftp_raw($this->connect, 'MLST ' . $path);
if (is_array($raw) && count($raw) > 1 && substr(trim($raw[0]), 0, 1) == 2) {
$parts = explode(';', trim($raw[1]));
array_pop($parts);
$parts = array_map('strtolower', $parts);
$stat = array();
foreach ($parts as $part) {
list($key, $val) = explode('=', $part);
switch ($key) {
case 'type':
$stat['mime'] = strpos($val, 'dir') !== false ? 'directory' : $this->mimetype($path);
break;
case 'size':
$stat['size'] = $val;
break;
case 'modify':
$ts = mktime(intval(substr($val, 8, 2)), intval(substr($val, 10, 2)), intval(substr($val, 12, 2)), intval(substr($val, 4, 2)), intval(substr($val, 6, 2)), substr($val, 0, 4));
$stat['ts'] = $ts;
break;
case 'unix.mode':
$stat['chmod'] = $val;
break;
case 'perm':
$val = strtolower($val);
$stat['read'] = (int) preg_match('/e|l|r/', $val);
$stat['write'] = (int) preg_match('/w|m|c/', $val);
if (!preg_match('/f|d/', $val)) {
$stat['locked'] = 1;
}
break;
}
}
if (empty($stat['mime'])) {
return array();
}
if ($stat['mime'] == 'directory') {
$stat['size'] = 0;
}
if (isset($stat['chmod'])) {
$stat['perm'] = '';
if ($stat['chmod'][0] == 0) {
$stat['chmod'] = substr($stat['chmod'], 1);
}
for ($i = 0; $i <= 2; $i++) {
$perm[$i] = array(false, false, false);
$n = isset($stat['chmod'][$i]) ? $stat['chmod'][$i] : 0;
if ($n - 4 >= 0) {
$perm[$i][0] = true;
$n = $n - 4;
$stat['perm'] .= 'r';
} else {
$stat['perm'] .= '-';
}
if ($n - 2 >= 0) {
$perm[$i][1] = true;
$n = $n - 2;
$stat['perm'] .= 'w';
} else {
$stat['perm'] .= '-';
}
if ($n - 1 == 0) {
$perm[$i][2] = true;
$stat['perm'] .= 'x';
} else {
$stat['perm'] .= '-';
}
$stat['perm'] .= ' ';
}
$stat['perm'] = trim($stat['perm']);
$owner = $this->options['owner'];
$read = $owner && $perm[0][0] || $perm[1][0] || $perm[2][0];
$stat['read'] = $stat['mime'] == 'directory' ? $read && ($owner && $perm[0][2] || $perm[1][2] || $perm[2][2]) : $read;
$stat['write'] = $owner && $perm[0][1] || $perm[1][1] || $perm[2][1];
unset($stat['chmod']);
}
return $stat;
}
return array();
}