Skip to content

Instantly share code, notes, and snippets.

@skobkin
Last active March 22, 2017 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skobkin/b35a011f6fde3e42a8293a9d6635e8c9 to your computer and use it in GitHub Desktop.
Save skobkin/b35a011f6fde3e42a8293a9d6635e8c9 to your computer and use it in GitHub Desktop.
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