Traverse path to make file
@param string $filePath path to file to check if it exists
@param string|null $content content of file to be written
@return bool|int
191557
public static function filePutContents($filePath, $content = null)
    {
        // https://stackoverflow.com/a/282140/405758
        if (!file_exists(dirname($filePath))) {
            mkdir(dirname($filePath), 0775, true);
        }
        return file_put_contents($filePath, $content);
    }
415811
public function parseFile($filePath, array $vars = [])
    {
        if (is_file($filePath)) {
            return $this->parseString(file_get_contents($filePath), $vars);
        }

        // Try to find from filePaths
        if (count($this->filePaths)) {
            foreach ($this->filePaths as $fileDirectory) {
                if (is_file($fileDirectory . $filePath)) {
                    return $this->parseString(file_get_contents($fileDirectory . $filePath), $vars);
                    break;
                }
            }
        }

        return null;
    }
176073
public function getFileContent( string$filePath ):string
	{
		return isset($this->fileGetter) ? $this->fileGetter($filePath) : file_get_contents($filePath);
	}
207327
public static function create(string $path, string $content = '', bool $overwrite = true): self
    {
        $path = normalize_path($path);

        if (is_file($path) && $overwrite) {
            self::unlink($path);
        }
        if (!is_file($path)) {
            if (is_writeable(dirname($path))) {
                if ($handle = fopen($path, 'w')) {
                    fwrite($handle, $content);
                    fclose($handle);

                    return new static($path);
                }
                throw new FileException('Creating file ('.$path.') failed');
            }
            throw new FileException('Cannot create file, because the directory ('.dirname($path).') is not accessible',
                FileException::NOT_WRITEABLE);
        }
        throw new FileException('Cannot create file, because the file path ('.$path.') already exist', FileException::ALREADY_EXIST);
    }
249707
public function save($path, $content)
    {
        $path = $this->getRealPath($path);
        if (!is_dir(dirname($path))) {
            @mkdir(dirname($path), 0755, true);
        }
        
        return file_put_contents($path, $content);
    }
556401
public function appendToFile($filename, $content)
    {
        if (\is_array($content)) {
            @trigger_error(sprintf('Calling "%s()" with an array in the $content argument is deprecated since Symfony 4.3.', __METHOD__), E_USER_DEPRECATED);
        }

        $dir = \dirname($filename);

        if (!is_dir($dir)) {
            $this->mkdir($dir);
        }

        if (!is_writable($dir)) {
            throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
        }

        if (false === @file_put_contents($filename, $content, FILE_APPEND)) {
            throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
        }
    }
1043111
public function extract($filePath)
    {
        $directory = $this->directory->getDirectoryPath();
        $pharArchive = new PharData($filePath, null, null, Phar::GZ);
        $pharArchive->extractTo($directory);

        return $this->createFinderFromDirectory($directory);
    }
51656
public function readFileFunc($filepath)
    {
        /** @var UniformResourceLocator $locator */
        $locator = $this->grav['locator'];

        if ($locator->isStream($filepath)) {
            $filepath = $locator->findResource($filepath);
        }

        if ($filepath && file_exists($filepath)) {
            return file_get_contents($filepath);
        }

        return false;
    }
708746
public function setFilepath(Path $filepath)
    {
        if ($this->filepath === null) {
            $this->filepath = $filepath;
        } else {
            $this->filepath->append($filepath);
        }
    }
1240281
private function tryWriteFile($path, $content) {
        $interval = 100000;
        $totalTime = 0;

        while (file_put_contents($path, $content) === false) {
            if ($totalTime >= $this->accessTime) {
                return false;
            }

            usleep($interval);

            $totalTime += $interval;
        }

        return true;
    }
994431
public function open(string $filePath, string $mode)
    {
        $this->exists($filePath, $mode);

        $ptr = @fopen($filePath, $mode);

        if (false === $ptr) {
            throw new FileException("Unable to open $filePath.");
        }

        return $ptr;
    }
1276972
protected function getFileAsset($filePath)
    {
        $file = new \SplFileInfo($filePath);

        if (!$file->isReadable() || $file->isDir()) {
            return null;
        }

        $filePath = $file->getRealPath();

        return new FileAsset($filePath);
    }
94028
public function extract($filePath)
    {
        $directory = $this->directory->getDirectoryPath();
        $zipArchive = new ZipArchive();
        $zipArchive->open($filePath);
        $zipArchive->extractTo($directory);

        return $this->createFinderFromDirectory($directory);
    }
924813
public static function countLines($filepath)
	{
		$return = false;
		if (file_exists($filepath)) {
			$handle = fopen($filepath, 'r');
			if ($handle) {
				$return = 0;
				while (!feof($handle)) {
					$chunk = fgets($handle, 4096);
					$chunk_count = substr_count($chunk, "\n");
					$return = $return + $chunk_count;
				}
				fclose($handle);
			}
		}
		return $return;
	}
588115
public function saveToFile($content, $additionalPath = '')
    {
        $path = $this->realPath($additionalPath);
        
        // If the path does not exists create the directory
        $this->createTargetDirectory($path);
        
        // If the file exists but isn't writeable we need to throw an exception
        if (file_exists($path) && !is_writable($path)) {
            throw new Exception('The file "' . $path . '" isn\'t writable!');
        }
        
        return file_put_contents($path, $content);
    }
1183525
public function sendFile($filePath, $fileName = null) {
        if (!file_exists($filePath))
            return false;

        if (empty($fileName))
            $fileName = basename($filePath);

        $this->addHeader("X-Sendfile: $filePath");
        $this->addHeader("Content-type: application/octet-stream");
        $this->addHeader('Content-Disposition: attachment; filename="'.$fileName.'"');
    }
118239
public function append($filename, $content)
    {
        if ($this->exists($filename) && $this->isFile($filename)) {
            return file_put_contents($filename, $content, FILE_APPEND);
        }

        throw new FileNotFoundException('File not found in the path [ ' . $filename . ' ].');
    }