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

File 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 File URIs, the library comes bundle with a URI specific File class.


In addition to the defined named constructors, because file path depends on the underlying OS, you can also instantiate a new File URI object from a file path using:


use League\Uri;

$uri = Uri\File::createFromWidowsPath('c:\windows\My Documents\my word.docx');
echo $uri; //returns 'file://localhost/c:My%20Documents/my%20word.docx'


Even though all URI properties are defined and accessible attempt to set any component other than the scheme, the host, and the path will result in the object throwing a InvalidArgumentException exception. As adding content to theses URI parts will generate an invalid File URI.


use League\Uri;

$uri = Uri\File::createFromUnixPath('/path/./../relative');
$uri->withQuery('foo=bar'); // will throw an League\Uri\UriException

URI normalization

If the host file is the empty string it will be converted to localhost.


use League\Uri;

$uri = Uri\File::createFromString('file:///path/to/file.csv');
echo $uri; //display file://localhost/path/to/file.csv