PHPackages                             waughj/file-loader - 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. waughj/file-loader

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

waughj/file-loader
==================

Object for easily generating image sources with autoversioning for handling cache corruption.

v0.5.4(6y ago)02896AGPL-3.0-or-laterPHPPHP &gt;=7.0

Since May 13Pushed 6y agoCompare

[ Source](https://github.com/waughjai/file-loader)[ Packagist](https://packagist.org/packages/waughj/file-loader)[ RSS](/packages/waughj-file-loader/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (5)Versions (12)Used By (6)

File Loader
===========

[](#file-loader)

Object for easily generating image sources with autoversioning for handling cache corruption.

Loader object takes in an optional hash map as its 1 argument ( though using this object without any arguments will just return the very string you give it from getSource ). The object will recognize any &amp; all o' 4 o' the following optional keys for that hash map:

- "directory-url": URL directory in which to look for file. If set, automatically appends this before given local filename. If none set, URL will just be the local.
- "directory-server": Server directory in which file is located. Used for finding modified time for this file, used for determining the "version" o' this file automatically for easy, automatic cache clearing when a file changes ( &amp; needs to be reloaded ). If not set, no versioning is used.
- "shared-directory": Directory that goes after both URL &amp; Server directories listed before.
- "extension": File extension to automatically add to end o' local file.

After setting this object up, you can use it to get sources for local filenames easily.

Example
-------

[](#example)

All CSS files are kept in /home/example.com/public\_html/assets/css &amp; are loaded from :

```
use WaughJ\FileLoader\FileLoader;

$loader = new FileLoader
([
	'directory-url' => 'https://www.example.com',
	'directory-server' => '/home/example.com/public_html',
	'shared-directory' => 'assets/css',
	'extension' => 'css'
]);

```

Then you can easily load files with just the local name with the "getSourceWithVersion" method:

```
// Get main CSS file
$loader->getSourceWithVersion( 'main' );

```

This will output "[https://www.example.com/assets/css/main.css?m={#######}](https://www.example.com/assets/css/main.css?m=%7B#######%7D)", with the #s being a long # representing the last modified time.

You can make new versions o' a loader with 1 o' the 4 attributes changed with the following methods, which return a new instance o' the loader object with all the other attributes the same:

- changeURLDirectory
- changeServerDirectory
- changeSharedDirectory
- changeExtension

To change multiple attributes easily, just chain them:

```
$loader2 = $loader1->changeURLDirectory( 'https:/www.new-website.com' )->changeExtension( 'sass' );

```

If you want to change the same loader, just set the loader equal to change, replacing the ol' instance with the new:

```
$loader1 = $loader1->changeURLDirectory( 'https:/www.new-website.com' )->changeExtension( 'sass' );

```

Error Handling
--------------

[](#error-handling)

The "getSourceWithVersion" method analyzes the file on the server's modified date to create the version string. If it can't access the file, it throws a WaughJ\\FileLoader\\MissingFileException exception, which includes the server &amp; url paths in it. If you want a safe way to fallback to versionless source without breaking the website or program, run a simple try &amp; catch &amp; in the catch use the exception object's "getFallbackContent" method to get the versionless source:

```
$file_url = null;
try
{
	$file_url = $loader->getSourceWithVersion( 'main' );
}
catch ( MissingFileException $e )
{
	// Perhaps run some logging code that logs that $e->getFilename() couldn't be found.

	// If exception is thrown, $file_url will be the equivalent o' $loader->getSource( 'main' ).
	$file_url = $e->getFallbackContent();
}

```

Changelog
---------

[](#changelog)

### 0.5.0

[](#050)

- Add Getter Methods &amp; Revamp Error Handling

### 0.4.0

[](#040)

- Add Ability to Get File Version

### 0.3.0

[](#030)

- Add Ability to Get Extension from Filename

### 0.2.0

[](#020)

- Add Change Methods

### 0.1.0

[](#010)

- Initial Version

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

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

Every ~2 days

Total

11

Last Release

2537d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11161078?v=4)[waughj](/maintainers/waughj)[@waughj](https://github.com/waughj)

---

Tags

loaderfile

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/waughj-file-loader/health.svg)

```
[![Health](https://phpackages.com/badges/waughj-file-loader/health.svg)](https://phpackages.com/packages/waughj-file-loader)
```

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k639.1M2.2k](/packages/league-flysystem)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.6k263.6M790](/packages/league-flysystem-aws-s3-v3)[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[knplabs/knp-gaufrette-bundle

Allows to easily use the Gaufrette library in a Symfony project

72528.6M91](/packages/knplabs-knp-gaufrette-bundle)[league/flysystem-local

Local filesystem adapter for Flysystem.

226231.8M39](/packages/league-flysystem-local)[league/flysystem-memory

In-memory filesystem adapter for Flysystem.

8533.6M194](/packages/league-flysystem-memory)

PHPackages © 2026

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