Library for generating unique file names.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/RM/Utils
tests
.gitattributes
.gitignore
.scrutinizer.yml
.travis.yml
README.md
composer.json
license.md

README.md

Unique

Build Status Code Quality Code Coverage Packagist

Uniqe is simple library for generating unique filenames in directories.

Requirements

Unique requires PHP 5.4 or later.

Installation

The best way to install Unique is use Composer package rm/unique or manual download the latest ZIP package from GitHub.

$ composer require rm/unique

Example

I need upload file something.png into directory /images.

If it is necessary to not overwrite existing files, you need to generate unique filenames.

Now it's simple!

$filename = Unique::get('something.png', '/images'); // return 'something.png'

And what if directory contains files something.png and for example, also something-1.png?

Returns something-2.png!

Unique::get() automatic generate filename in format <filename><separator><order>.<extension> and check if exists in specified directory. If is unique, return it.

API

get()

Method get() has two parameters:

  • string $filename Name of file
  • string $dir Directory where will be file saved

Return

  • string Output filename

$separator

Default separator of filename and order it's -. It's possible change it, for example:

Unique::$separator = '|';

Contributing

  • Use it!
  • Write bug reports of ideas into Issue tracker.
  • Fork repos and send pull requests with number of issue, source code and tests.

Contact

Roman Mátyus romanmatyus@romiix.org