src/CarteBlanche/Library/File.php
public static function createFromContent( $file_content, $filename=null, $client_file_name=null )
    {
        $finfo = new \finfo();
        $mime = $finfo->buffer( $file_content, FILEINFO_MIME_TYPE );
        $extension = end(explode('/', $mime));
        if (is_null($filename)) {
            $_tmp_filename = md5( $file_content ).'.'.$extension;
            $filename = CarteBlanche::getFullPath('web_tmp_dir').$_tmp_filename;
            if (file_exists($filename)) {
                return new File( $filename, $client_file_name );
            }
        } elseif (end(explode('.', $filename))!=$extension) {
            $filename .= '.'.$extension;
        }

        $_tf = fopen($filename, 'a+');
        if ($_tf) {
            fwrite($_tf, $file_content);
            fclose($_tf);
            return new File( $filename, $client_file_name );
        }
        return null;
    }
public static function createFromContent( $file_content, $filename=null, $client_file_name=null )
    {
        $finfo = new \finfo();
        $mime = $finfo->buffer( $file_content, FILEINFO_MIME_TYPE );
        $extension = end(explode('/', $mime));
        if (is_null($filename)) {
            $_tmp_filename = md5( $file_content ).'.'.$extension;
            $filename = CarteBlanche::getFullPath('web_tmp_dir').$_tmp_filename;
            if (file_exists($filename)) {
                return new File( $filename, $client_file_name );
            }
        } elseif (end(explode('.', $filename))!=$extension) {
            $filename .= '.'.$extension;
        }

        $_tf = fopen($filename, 'a+');
        if ($_tf) {
            fwrite($_tf, $file_content);
            fclose($_tf);
            return new File( $filename, $client_file_name );
        }
        return null;
    }
Create a file with a content string and returns the created filename

@param   string  $file_content   The source file content
@param   string  $filename       The target filename (optional - automatic if not set)
@return  \CarteBlanche\Library\File