Skip to content

Instantly share code, notes, and snippets.

@christianseel
Created March 13, 2015 14:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianseel/ab6efa9c69cb34f66472 to your computer and use it in GitHub Desktop.
Save christianseel/ab6efa9c69cb34f66472 to your computer and use it in GitHub Desktop.
fix file and folder permissions for MODX
<?php
switch($modx->event->name) {
case 'OnFileManagerDirCreate':
$modx->log(modX::LOG_LEVEL_ERROR, 'fix folder permissions for: '.$directory.'/');
chmod($directory.'/', octdec($modx->getOption('new_folder_permissions')));
break;
case 'OnFileManagerFileCreate':
$modx->log(modX::LOG_LEVEL_ERROR, 'fix file permissions for: '.$path);
chmod($path, octdec($modx->getOption('new_file_permissions')));
break;
case 'OnFileManagerUpload':
$full_path = $modx->getOption('assets_path') .'uploads/'. $directory;
if (file_exists($full_path.$files['file']['name'])) {
$modx->log(modX::LOG_LEVEL_ERROR, 'fix file permissions for uploaded file: '.$full_path.$files['file']['name']);
chmod($full_path.$files['file']['name'], octdec($modx->getOption('new_file_permissions')));
} else {
$modx->log(modX::LOG_LEVEL_ERROR, 'Can\'t file permissions because: File not found! Full path: '. $full_path.$files['file']['name'] .' Directory: '.$directory. ' File data: '.json_encode($files));
}
break;
}
return;
@thijsvandamme
Copy link

On what event is this plugin listening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment