Check if directory of file resource is trusted.

@param  string $filepath

@return boolean         true if directory is trusted
@throws SmartyException if PHP directory is not trusted
550151
public function isTrustedPHPDir($filepath)
    {
        if (empty($this->trusted_dir)) {
            throw new SmartyException("directory '{$filepath}' not allowed by security setting (no trusted_dir specified)");
        }

        // check if index is outdated
        if (!$this->_trusted_dir || $this->_trusted_dir !== $this->trusted_dir) {
            $this->_php_resource_dir = array();

            $this->_trusted_dir = $this->trusted_dir;
            foreach ((array) $this->trusted_dir as $directory) {
                $directory = realpath($directory);
                $this->_php_resource_dir[$directory] = true;
            }
        }

        $_filepath = realpath($filepath);
        $directory = dirname($_filepath);
        $_directory = array();
        while (true) {
            // remember the directory to add it to _resource_dir in case we're successful
            $_directory[] = $directory;
            // test if the directory is trusted
            if (isset($this->_php_resource_dir[$directory])) {
                // merge sub directories of current $directory into _resource_dir to speed up subsequent lookup
                $this->_php_resource_dir = array_merge($this->_php_resource_dir, $_directory);

                return true;
            }
            // abort if we've reached root
            if (($pos = strrpos($directory, DS)) === false || !isset($directory[2])) {
                break;
            }
            // bubble up one level
            $directory = substr($directory, 0, $pos);
        }

        throw new SmartyException("directory '{$_filepath}' not allowed by security setting");
    }
951188
public function fileExists($path) {

        $ch = curl_init($this->hostUrl . "/" . $this->siteFolder . $path);

        curl_setopt($ch, CURLOPT_NOBODY, true);

        $result = curl_exec($ch);
        $ret = false;

        if($result !== false) {
        $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        if($status == 200) {
            $ret = true;
        }
        }

        curl_close($ch);

        return $ret;
    }
27412
public static function openFile(/*string*/ $filePath, /*string*/ $mode) {
    return self::isFile($filePath) ? fopen($filePath, $mode, false) : false;
  }
1359576
public function isDir($directory)
    {
        $pwd = $this->ftp->pwd();

        if ($pwd === false) {
            throw new FtpException('Unable to resolve the current directory');
        }

        if (@$this->ftp->chdir($directory)) {
            $this->ftp->chdir($pwd);
            return true;
        }

        $this->ftp->chdir($pwd);

        return false;
    }
90481
public static function mkdir($filePath, $mode = 0777) {
        if (empty($filePath)) {
            return false;
        }
        if (!file_exists($filePath)) {
            mkdir($filePath, $mode);
        }
        return true;
    }
762866
public static function unlinkSafe(string $filePath) : bool
    {
        if (!FileHelper::fileExistsSafe($filePath)) {
            return false;
        }

        if (DirHelper::isDirSafe($filePath)) {
            return false;
        }

        return unlink($filePath);
    }
766072
protected function checkFileDate($fileList, $referenceFile) {
    foreach ($fileList as $file) {
      if (@filemtime($file) > @filemtime($referenceFile)) {
        return true;
      }
    }
    return false;
  }
1253453
protected function isWithinFilesystem($path)
    {
        $pathUrl = new Url($path);
        $fsUrl = $this->filesystem->url();

        if (!$pathUrl->scheme) {
            $pathUrl = $pathUrl->scheme('file');
        }

        if (!$fsUrl->scheme) {
            $fsUrl = $fsUrl->scheme('file');
        }

        if ($pathUrl->scheme != $fsUrl->scheme) {
            return false;
        }

        if (Helper::startsWith("$pathUrl->path", "$fsUrl->path")) {
            return true;
        }

        return $this->filesystem->exists($path);
    }
201643
protected function buildDirectory($filePath)
	{
		$directory = dirname($filePath);
		
		if (!is_dir($directory)) {
			mkdir($directory, 0777, true);
		}
	}
319279
protected function isDirectory($path)
    {
        $location = $this->applyPathPrefix($path);

        if (empty($location)) {
            return true;
        }

        try {
            $file = $this->share->stat($location);
        } catch (NotFoundException $e) {
            return false;
        }

        return $file->isDirectory();
    }
1050780
protected function verifyPath($path){
		if (file_exists($path)) return true;
			
		if (mkdir($path, 0777, true)) return true;
				
		return false;
	}
352402
protected function validateFilePath($filePath)
    {
        if (false === (\is_dir($filePath) && \is_writable($filePath))) {
            throw new SitemapException(
                \sprintf("Provided path '%s' does not exist or is not writable.", $filePath)
            );
        }
    }
368461
public function uploadFile(string $dirPath, string $fileName): bool
    {
        try {
            if (!$this->filesystem->createDir($dirPath)) {
                return false;
            }

            $targetFilePath = $dirPath . DIRECTORY_SEPARATOR . $fileName;

            if ($this->filesystem->has($targetFilePath)) {
                $this->addError('', "File by path `{$targetFilePath}` already exists.");

                return false;
            }

            $contentResource = $this->getFileContent();
            if ($contentResource === null) {
                return false;
            }

            return $this->filesystem->writeStream($targetFilePath, $contentResource);
        } catch (\Exception $e) {
            return false;
        }
    }
28051
public function filePutContents($filePath, $data)
    {
        $bytesWritten = @file_put_contents($filePath, $data);
        if ($bytesWritten === false) {
            throw new FileSystemException('File '.$filePath.' could not be written');
        }
        return true;
    }
729890
public function isFile($filePath)
	{
		if (substr($filePath, 0, 1) != '/') {
			$filePath = '/'.$filePath;
		}
		return is_file('s3://'.$this->getBucket().$filePath);
	}
851919
public function isFileAllowed($filePath)
    {
        $filePath = realpath($filePath);
        foreach ($this->allowedImageFolders as $key => $nextFolder) {
            if (0 === strpos($filePath, $nextFolder)) {
                return $key;
            }
        }

        return false;
    }
9982
private function fileContains($filePath, $text) {
		$fileData = file_get_contents($filePath);
		if (strpos($fileData, $text) === false ) {
			return true;
		} else {
			return false;
		}
	}