rm / unique
Library for generating unique file names.
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: 2024-12-05 20:43:33 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
$filename
Name of filestring
$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