PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Glob> <Compression Streams
Last updated: Fri, 10 Oct 2008

view this page in

Data (RFC 2397)

The data: (» RFC 2397) stream wrapper is available since PHP 5.2.0.

Example #1 Print data:// contents

<?php
// prints "I love PHP"
echo file_get_contents('data://text/plain;base64,SSBsb3ZlIFBIUAo=');
?>

Example #2 Fetch the media type

<?php
$fp   
fopen('data://text/plain;base64,''r');
$meta stream_get_meta_data($fp);

// prints "text/plain"
echo $meta['mediatype'];
?>

Wrapper Summary
Attribute Supported
Restricted by allow_url_fopen No
Restricted by allow_url_include Yes
Allows Reading Yes
Allows Writing No
Allows Appending No
Allows Simultaneous Reading and Writing No
Supports stat() No
Supports unlink() No
Supports rename() No
Supports mkdir() No
Supports rmdir() No



add a note add a note User Contributed Notes
Data (RFC 2397)
sandaimespaceman at gmail dot com
06-Sep-2008 10:30
Now PHP supports data: protocol w/out "//" like data:text/plain, not data://text/plain,

I tried it.
togos00 at gmail dot com
08-Apr-2008 04:56
Note that the official data URI scheme does not include a double slash after the colon - that you must include it when making calls to PHP is an artifact of the designers' misunderstanding of URL syntax.

To automatically convert proper data URIs to ones understood by PHP, you can use code such as the following:

function convertUriForPhp( $uri ) {
    if( preg_match('/^data:(?!\\/\\/)(.*)$/',$uri,$bif) ) {
        return 'data://' . $bif[1];
    } else {
        return $uri;
    }
}

Glob> <Compression Streams
Last updated: Fri, 10 Oct 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites