PHPackages                             peterpostmann/fileuri - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. peterpostmann/fileuri

ActiveLibrary[File &amp; Storage](/categories/file-storage)

peterpostmann/fileuri
=====================

Returns a file uri from a (relative) path

1.0.0(8y ago)02304MITPHP

Since Nov 5Pushed 8y ago1 watchersCompare

[ Source](https://github.com/peterpostmann/php-fileuri)[ Packagist](https://packagist.org/packages/peterpostmann/fileuri)[ RSS](/packages/peterpostmann-fileuri/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (2)Used By (4)

fileuri
=======

[](#fileuri)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/7056a73b71734901a720bdaa145d9c38d86297745a278fc8fce46619ac00aff0/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7065746572706f73746d616e6e2f7068702d66696c657572692f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/peterpostmann/php-fileuri)

Returns a file uri from a (relative) path

Install
-------

[](#install)

### Via Composer

[](#via-composer)

```
composer require peterpostmann/fileuri
```

If you dont want to use composer just copy the `fileuri.php` file and include it into your project.

Why
---

[](#why)

This function can be used to create [RFC3986](https://tools.ietf.org/html/rfc3986/) complient file URIs and build protocol agnostic functions.

```
function parseReference($ref)
{
    list($prefix, $path) = explode('://', $ref, 2);
    return [$prefix, $path];
}

var_dump(parseReference('https://server.tld/path/ressource.ext'));
var_dump(parseReference('file:///path/to/file.ext'));
```

The above example will output:

```

array (size=2)
  0 => string 'https' (length=5)
  1 => string 'server.tld/path/ressource.ext' (length=29)

array (size=2)
  0 => string 'file' (length=4)
  1 => string '/path/to/file.ext (length=17)

```

If you want to examine URIs of multiple protocols this cannot be done easily because PHP does not return rfc3986 compliant URIs for files. PHP returns different formats depending on the file location and platform ()

```
use Sabre\Uri;

function parseReference($uri)
{
    return Uri\parse($uri);
}
```

Usage
-----

[](#usage)

```
use function peterpostmann\fileuri;

string fileuri ( string path [, string basePath] )
```

### Example

[](#example)

### Sample Output

[](#sample-output)

```
use function peterpostmann\fileuri;

// Absolute Path
echo fileuri('/path/to/file.ext');
echo fileuri('C:\path\to\winfile.ext');
echo fileuri('\\\\smbserver\share\path\to\winfile.ext');

// Relative Path with base path
echo fileuri('relative/path/to/file.ext', '/');
echo fileuri('fileInCwd.ext','C:\testfolder);

// Path that is already a URI
echo fileuri('file:///path/to/file.ext');
```

The above example will output:

```

file:///path/to/file.ext
file:///C:/path/to/winfile.ext
file:///C:/path/to/winfile.ext
file://smbserver/share/path/to/winfile.ext
file:///relative/path/to/file.ext
file:///C:/testfolder/fileInCwd.ext
file:///path/to/file.ext

```

### Error Output

[](#error-output)

The function returns false if a relative path is given without a base path.

```
use function peterpostmann\fileuri;

// Relative Path without base path
var_dump(fileuri('relative/path/to/file.ext'));
```

The above example will output:

```

boolean false

```

### Usage with file functions

[](#usage-with-file-functions)

```
use function peterpostmann\fileuri;

// Absolute Path
$uri = fileuri('/path/to/file.ext');

var_dump(file_get_contents(urldecode($uri)));
```

`file_get_contents` does not normalize urls, therefore file URIs cannot be used directly.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3113d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9362588b9edca85b56850256b890ab5e0f94670fa50e460a9547192785eb880b?d=identicon)[peterpostmann](/maintainers/peterpostmann)

---

Top Contributors

[![peterpostmann](https://avatars.githubusercontent.com/u/9541377?v=4)](https://github.com/peterpostmann "peterpostmann (6 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/peterpostmann-fileuri/health.svg)

```
[![Health](https://phpackages.com/badges/peterpostmann-fileuri/health.svg)](https://phpackages.com/packages/peterpostmann-fileuri)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M125](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
