src/File.php
public function encode($filePath) {
        if (!file_exists($filePath) ||
            !is_readable($filePath)) {
            throw new BadMethodCallException(sprintf(
                'File "%s" not found or not readable',
                $filePath
            ));
        }

        $fileContent = file_get_contents($filePath);

        if (!is_string($fileContent)) {
            throw new RuntimeException(sprintf(
                'Unable to read from file "%s"',
                $filePath
            ));
        }

        $fileAsString = base64_encode($fileContent);

        return $fileAsString;
    }
public function encode($filePath) {
        if (!file_exists($filePath) ||
            !is_readable($filePath)) {
            throw new BadMethodCallException(sprintf(
                'File "%s" not found or not readable',
                $filePath
            ));
        }

        $fileContent = file_get_contents($filePath);

        if (!is_string($fileContent)) {
            throw new RuntimeException(sprintf(
                'Unable to read from file "%s"',
                $filePath
            ));
        }

        $fileAsString = base64_encode($fileContent);

        return $fileAsString;
    }
public function encode ( $ filePath ) { if ( ! file_exists ( $ filePath ) || ! is_readable ( $ filePath ) ) { throw new BadMethodCallException ( sprintf ( 'File "%s" not found or not readable' , $ filePath ) ) ; } $ fileContent = file_get_contents ( $ filePath ) ; if ( ! is_string ( $ fileContent ) ) { throw new RuntimeException ( sprintf ( 'Unable to read from file "%s"' , $ filePath ) ) ; } $ fileAsString = base64_encode ( $ fileContent ) ; return $ fileAsString ; }
Encode an file to base64

@param string $filePath Path to file

@return string Base64 encoded string

@throws Exception on error
Encode an file to base64