Skip to content

Instantly share code, notes, and snippets.

@skobkin skobkin/UniqNamer.php
Last active Mar 22, 2017

Embed
What would you like to do?
iphp file uploader custom namer
# ./app/config/config.yml
parameters:
iphp.filestore.namer.default.class: Skobkin\Bundle\FileUploadBundle\Naming\UniqNamer
# ...
iphp_file_store:
mappings:
mod_title_image:
upload_dir: %kernel.root_dir%/../web/uploads/mods/titles
upload_path: /uploads/mods/titles
namer:
uniqid: ~
<?php
// src/Skobkin/Bundle/FileUploadBundle/Naming/UniqNamer.php
namespace Skobkin\Bundle\FileUploadBundle\Naming;
use Iphp\FileStoreBundle\Mapping\PropertyMapping;
use Iphp\FileStoreBundle\Naming\DefaultNamer;
class UniqNamer extends DefaultNamer
{
/**
* Rename file name based on uniqid()
*
* @param $name
* @param $params
*
* @return string
*/
function uniqidRename(PropertyMapping $propertyMapping, $name, $params)
{
// Unique id and extension
$newName = uniqid(null, true) . substr($name, strrpos($name, '.'));
return $newName;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.