Ftp URI
To ease working with FTP URIs, the library comes bundle with a URI specific FTP class League\Uri\Schemes\Ftp
.
Validation
A FTP URI must contain the ftp
scheme. It can not contains a query and or a fragment component.
<?php
use League\Uri\Schemes\Ftp as FtpUri;
$uri = FtpUri::createFromString('ftp://thephpleague.com/path/to/image.png;type=i');
$uri->withQuery('p=1'); //throw an InvalidArgumentException - a query component was given
Apart from the fragment and the query components, the Ftp URIs share the same host validation limitation as Http URIs.
Properties
The FTP URI class uses the specialized HierarchicalPath class to represents its path. using PHP’s magic __get
method you can access the object path and get more informations about the underlying path.
<?php
use League\Uri\Schemes\Ftp as FtpUri;
$uri = FtpUri::createFromString('ftp://thephpleague.com/path/to/image.png;type=i');
echo $uri->path->getBasename(); //display 'image.png;type=i'
echo $uri->path->getDirname(); //display '/path/to'
echo $uri->path->getExtension(); //display 'png'
$uri->path->getSegments(); //returns an array representation of the path segments