HEX
HEX
Server: Apache
System: Linux localhost.localdomain 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64
User: www (1001)
PHP: 8.1.32
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/ahmsolaiman.com/wp-content/plugins/types/application/models/Filesystem/Directory.php
<?php

namespace OTGS\Toolset\Types\Filesystem;

use DirectoryIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use Toolset_Filesystem_Exception;

class Directory {

	private $path = false;


	/**
	 * Open file by path and stores it on success.
	 *
	 * @param string $path
	 *
	 * @return bool
	 */
	public function open( $path ) {

		if ( ! is_dir( $path ) || ! is_readable( $path ) ) {
			return false;
		}

		$this->path = $path;

		return true;
	}


	/**
	 * @param string $filename
	 * @param bool $recursive
	 *
	 * @return array|bool|DirectoryIterator
	 * @throws Toolset_Filesystem_Exception
	 */
	public function find( $filename, $recursive = false ) {

		// skip if path is not set
		if ( ! $this->path ) {
			throw new Toolset_Filesystem_Exception( 'No directory is selected.' );
		}

		// if using recursive flag
		if ( $recursive ) {
			return $this->find_recursive( $filename );
		}

		// search in directory
		foreach ( new DirectoryIterator( $this->path ) as $file ) {
			// check current is not a directory and match with filename
			if ( $file->getFilename() === $filename && ! is_dir( $file->getRealPath() ) ) {
				return $file;
			}
		}

		// file not found in root directory
		return false;
	}


	/**
	 * @param string $filename
	 *
	 * @return array|bool
	 * @throws Toolset_Filesystem_Exception
	 */
	public function find_recursive( $filename ) {

		// skip if path is not set
		if ( ! $this->path ) {
			throw new Toolset_Filesystem_Exception( 'No directory is selected.' );
		}

		// use $this->path as directory
		$directory = new RecursiveDirectoryIterator( $this->path );

		$files_found = array();

		// search recursive in directory
		foreach ( new RecursiveIteratorIterator( $directory ) as $file ) {
			if ( $file->getFilename() === $filename && ! is_dir( $file->getRealPath() ) ) {
				$files_found[] = $file;
			}
		}

		if ( empty( $files_found ) ) {
			return false;
		}

		return $files_found;
	}
}

/** @noinspection PhpIgnoredClassAliasDeclaration */
class_alias( Directory::class, 'Toolset_Filesystem_Directory' );