Last active
March 22, 2017 14:09
-
-
Save skobkin/b35a011f6fde3e42a8293a9d6635e8c9 to your computer and use it in GitHub Desktop.
iphp file uploader custom namer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ./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: ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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