JBZoo\Utils\FS::openFile PHP Method

openFile() public static method

Binary safe to open file
public static openFile ( $filepath ) : null | string
$filepath
return null | string
    public static function openFile($filepath)
    {
        $contents = null;
        if ($realPath = realpath($filepath)) {
            $handle = fopen($realPath, "rb");
            $contents = fread($handle, filesize($realPath));
            fclose($handle);
        }
        return $contents;
    }

Usage Example

Example #1
0
<?php

/**
 * JBZoo CrossCMS
 *
 * This file is part of the JBZoo CCK package.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @package   CrossCMS
 * @license   MIT
 * @copyright Copyright (C) JBZoo.com,  All rights reserved.
 * @link      https://github.com/JBZoo/CrossCMS
 * @author    Denis Smetannikov <*****@*****.**>
 */
use JBZoo\Utils\FS;
require_once realpath('./vendor/autoload.php');
$configPath = FS::real('./resources/joomla/configuration.php');
if ($configPath) {
    $config = FS::openFile($configPath);
    $config = preg_replace('#\'smtp\'#ius', "'mail'", $config);
    $config = preg_replace('#\'default\'#ius', "'development'", $config);
    file_put_contents($configPath, $config);
} else {
    throw new \Exception('Joomla configuration file not found!');
}
All Usage Examples Of JBZoo\Utils\FS::openFile