82 private $_streamException;
91 if ($this->_streamHandler) {
104 if (!$this->_streamHandler) {
107 $this->_streamLocked =
true;
108 $lock = $exclusive ? LOCK_EX : LOCK_SH;
109 return flock($this->_streamHandler, $lock);
119 if (!$this->_streamHandler || !$this->_streamLocked) {
122 $this->_streamLocked =
false;
123 return flock($this->_streamHandler, LOCK_UN);
134 if (!$this->_streamHandler) {
137 if (
feof($this->_streamHandler)) {
140 return @fgets($this->_streamHandler, $length);
152 if (!$this->_streamHandler) {
155 return @fgetcsv($this->_streamHandler, 0, $delimiter, $enclosure);
166 if (!$this->_streamHandler) {
169 return @
fwrite($this->_streamHandler, $str);
180 public function streamWriteCsv(array
$row, $delimiter =
',', $enclosure =
'"')
182 if (!$this->_streamHandler) {
195 if (isset(
$value[0]) && in_array(
$value[0], [
'=',
'+',
'-'])) {
199 return @fputcsv($this->_streamHandler,
$row, $delimiter, $enclosure);
210 if (!$this->_streamHandler) {
214 if ($this->_streamLocked) {
217 @fclose($this->_streamHandler);
218 $this->
chmod($this->_streamFileName, $this->_streamChmod);
231 if (!$this->_streamHandler) {
234 $stat = @fstat($this->_streamHandler);
235 if ($part !==
null) {
236 return $stat[$part] ?? $default;
248 return $this->_streamException;
260 public function open(array $args = [])
262 if (!empty($args[
'path'])) {
264 if ($this->_allowCreateFolders) {
265 $this->_createDestinationFolder($args[
'path']);
270 $this->
_iwd = getcwd();
271 $this->
cd(!empty($args[
'path']) ? $args[
'path'] : $this->
_iwd);
284 $this->_allowCreateFolders = $flag;
321 public function rmdir($dir, $recursive =
false)
362 if (empty($fileCallback) || !is_array($fileCallback) || !is_array($dirCallback)) {
363 throw new \InvalidArgumentException(
"file/dir callback is not specified");
365 if (empty($dirCallback)) {
366 $dirCallback = $fileCallback;
369 foreach (scandir($dir, SCANDIR_SORT_NONE) as
$item) {
370 if (!strcmp(
$item,
'.') || !strcmp(
$item,
'..')) {
375 $callback = $dirCallback[0];
376 if (!is_callable($callback)) {
377 throw new \InvalidArgumentException(
"'dirCallback' parameter is not callable");
379 $parameters = isset($dirCallback[1]) ? $dirCallback[1] : [];
381 $callback = $fileCallback[0];
382 if (!is_callable($callback)) {
383 throw new \InvalidArgumentException(
"'fileCallback' parameter is not callable");
385 $parameters = isset($fileCallback[1]) ? $fileCallback[1] : [];
387 array_unshift($parameters, $dir);
388 $result = @call_user_func_array($callback, $parameters);
411 public function cd($dir)
415 $this->
_cwd = realpath($dir);
418 throw new \Exception(
'Unable to list current working directory.');
432 public function read($filename, $dest =
null)
435 if ($dest !==
null) {
436 $result = @copy($filename, $dest);
457 $src = realpath($src);
466 if (file_exists($filename)) {
467 if (!is_writeable($filename)) {
468 printf(
'The file %s is not writable', $filename);
473 printf(
'The directory %s is not writable',
dirname($filename));
478 $result = @copy($src, $filename);
529 preg_match(
'/^(.*[!\/])/', $filePath, $matches);
530 if (isset($matches[0])) {
544 if (!$this->_allowCreateFolders) {
567 throw new \Exception(
"Unable to create directory '{$folder}'. Access forbidden.");
578 private function _createDestinationFolder($destinationFolder)
590 public function rm($filename)
606 public function mv($src, $destination)
609 $result = @rename($src, $destination);
622 public function cp($src, $destination)
625 $result = @copy($src, $destination);
679 public function ls($grep =
null)
681 $ignoredDirectories = [
'.',
'..'];
688 throw new \Exception(
'Unable to list current working directory.');
693 $dirHandler = opendir($dir);
695 while (($entry = readdir($dirHandler)) !==
false) {
698 $fullPath = $dir .
'/' . $entry;
700 if ($grep == self::GREP_DIRS && !
is_dir($fullPath)) {
702 }
elseif ($grep == self::GREP_FILES && !
is_file($fullPath)) {
704 }
elseif (in_array($entry, $ignoredDirectories)) {
708 $listItem[
'text'] = $entry;
709 $listItem[
'mod_date'] = date(
'Y-m-d H:i:s', filectime($fullPath));
714 $pathInfo = pathinfo($fullPath);
715 $listItem[
'size'] =
filesize($fullPath);
716 $listItem[
'leaf'] =
true;
718 $pathInfo[
'extension']
720 strtolower($pathInfo[
'extension']),
721 [
'jpg',
'jpeg',
'gif',
'bmp',
'png']
722 ) && $listItem[
'size'] > 0
724 $listItem[
'is_image'] =
true;
725 $listItem[
'filetype'] = $pathInfo[
'extension'];
726 }
elseif ($listItem[
'size'] == 0) {
727 $listItem[
'is_image'] =
false;
728 $listItem[
'filetype'] =
'unknown';
729 }
elseif (isset($pathInfo[
'extension'])) {
730 $listItem[
'is_image'] =
false;
731 $listItem[
'filetype'] = $pathInfo[
'extension'];
733 $listItem[
'is_image'] =
false;
734 $listItem[
'filetype'] =
'unknown';
737 $listItem[
'leaf'] =
false;
738 $listItem[
'id'] = $fullPath;
743 closedir($dirHandler);
745 throw new \Exception(
'Unable to list current working directory. Access forbidden.');
786 if (
$mode & 0x1000) {
805 $owner[
'read'] =
$mode & 00400 ?
'r' :
'-';
806 $owner[
'write'] =
$mode & 00200 ?
'w' :
'-';
807 $owner[
'execute'] =
$mode & 00100 ?
'x' :
'-';
811 $world[
'read'] =
$mode & 00004 ?
'r' :
'-';
812 $world[
'write'] =
$mode & 00002 ?
'w' :
'-';
813 $world[
'execute'] =
$mode & 00001 ?
'x' :
'-';
817 $owner[
"execute"] = $owner[
'execute'] ==
'x' ?
's' :
'S';
820 $group[
"execute"] =
$group[
'execute'] ==
'x' ?
's' :
'S';
823 $world[
"execute"] = $world[
'execute'] ==
'x' ?
't' :
'T';
826 $s = sprintf(
'%1s',
$type);
827 $s .= sprintf(
'%1s%1s%1s', $owner[
'read'], $owner[
'write'], $owner[
'execute']);
829 $s .= sprintf(
'%1s%1s%1s', $world[
'read'], $world[
'write'], $world[
'execute']);
845 $owner = posix_getpwuid(fileowner($filename));
846 $groupInfo = posix_getgrnam(filegroup($filename));
848 return $owner[
'name'] .
' / ' . $groupInfo;
892 return pathinfo(
$path);
fileExists($file, $onlyFile=true)
createDestinationDir($path)
streamStat($part=null, $default=null)
read($filename, $dest=null)
setAllowCreateFolders($flag)
elseif(isset( $params[ 'redirect_parent']))
static _recursiveCallback($dir, array $fileCallback, array $dirCallback=[])
checkAndCreateFolder($folder, $mode=0777)
chmod($filename, $mode, $recursive=false)
getDirectoriesList($path, $flag=GLOB_ONLYDIR)
streamReadCsv($delimiter=',', $enclosure='"')
getDestinationFolder($filePath)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
rmdir($dir, $recursive=false)
mkdir($dir, $mode=0777, $recursive=true)
streamLock($exclusive=true)
write($filename, $src, $mode=null)
static chmodRecursive($dir, $mode)
static rmdirRecursive($dir, $recursive=true)