Unique
, (*1)
Uniqe is simple library for generating unique filenames in directories., (*2)
Requirements
Unique requires PHP 5.4 or later., (*3)
Installation
The best way to install Unique is use Composer package rm/unique
or manual download the latest ZIP package from GitHub., (*4)
$ composer require rm/unique
Example
I need upload file something.png
into directory /images
., (*5)
If it is necessary to not overwrite existing files, you need to generate unique filenames., (*6)
Now it's simple!, (*7)
$filename = Unique::get('something.png', '/images'); // return 'something.png'
And what if directory contains files something.png
and for example, also something-1.png
?, (*8)
Returns something-2.png
!, (*9)
Unique::get()
automatic generate filename in format <filename><separator><order>.<extension>
and check if exists in specified directory. If is unique, return it., (*10)
API
get()
Method get()
has two parameters:, (*11)
-
string
$filename
Name of file
-
string
$dir
Directory where will be file saved
Return, (*12)
$separator
Default separator
of filename and order it's -
. It's possible change it, for example:, (*13)
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.
Roman Mátyus romanmatyus@romiix.org, (*14)