rm / unique
Library for generating unique file names.
Installs: 195
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/rm/unique
Requires
- php: >=5.4
Requires (Dev)
- jakub-onderka/php-parallel-lint: ~0.8
- nette/tester: @dev
- nette/utils: >=2.2
This package is auto-updated.
Last update: 2025-10-05 22:37:19 UTC
README
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$filenameName of filestring$dirDirectory where will be file saved
Return
stringOutput 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