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