The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages

Getting Started

Uri functions

Uri parser

Uri schemes

Uri manipulations

Uri components

Uri Domain Parser

Upgrading Guide

Data URI

Starting with version 1.1.0 all URI objects are defined in the League\Uri namespace. The League\Uri\Schemes namespace is deprecated and will be removed in the next major release.

To ease working with Data URIs, the library comes bundle with a URI specific Data class. This class follows RFC2397


In addition to the defined named constructors, because data URI represents files, you can also instantiate a new data URI object from a file path using the createFromPath named constructor


use League\Uri;

$uri = Uri\Data::createFromPath('path/to/my/png/image.png');
echo $uri; //returns 'data:image/png;charset=binary;base64,...'
//where '...' represent the base64 representation of the file

If the file is not readable or accessible an UriException exception will be thrown. The class uses PHP’s finfo class to detect the required mediatype as defined in RFC2045.


Even though all URI properties are defined and accessible attempt to set any component other than the path will result in the object throwing a UriException exception. As adding data to theses URI parts will generate an invalid Data URI.


use League\Uri;

$uri = Uri\Data::createFromPath('path/to/my/png/image.png');
$uri->getHost(); //return '' an empty string
$uri->withHost(''); // will throw an League\Uri\UriException