Skip to content

Instantly share code, notes, and snippets.

@dopsmain
Created July 6, 2016 10:24
Show Gist options
  • Save dopsmain/2877505d1afef8a9103e4668d55decae to your computer and use it in GitHub Desktop.
Save dopsmain/2877505d1afef8a9103e4668d55decae to your computer and use it in GitHub Desktop.
<?php
/*
* OnFileManagerUpload.
*/
switch ($modx->event->name) {
case 'OnFileManagerUpload':
$generator = $modx->newObject('modResource');
$bases = $source->getBases($directory);
$fullPath = $bases['pathAbsolute'].ltrim($directory,'/');
$directory = $source->fileHandler->make($fullPath);
foreach ($files as $file) {
$ext = @pathinfo($file['name'],PATHINFO_EXTENSION);
rename($directory->getPath().$file['name'], $directory->getPath() .
str_replace($ext, '.'.$ext, $generator->cleanAlias($file['name'])));
}
break;
default: break;
}
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment