Skip to content

Instantly share code, notes, and snippets.

@av-jok
Created March 27, 2016 12:29
Show Gist options
  • Save av-jok/675ce225a125dd8f113b to your computer and use it in GitHub Desktop.
Save av-jok/675ce225a125dd8f113b to your computer and use it in GitHub Desktop.
Translit non-latin (cyrillic etc.) names of uploadig files to latin with timestamp by modx cleanAlias()
<?php
//Привязывать к событию OnFileManagerUpload.
$currentdoc = $modx->newObject('modResource');
foreach($files as $file)
{
if($file['error'] == 0)
{
$pathInfo = pathinfo($file['name']);
$oldPath = $directory.$file['name'];
$newPath = date("Y-m-d-h-s-").$currentdoc->cleanAlias($pathInfo['filename']).'.'. $pathInfo['extension'];
$source->renameObject($oldPath, $newPath);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment