I would like to restrict IMCE users to a certain directory based on the content type that the WYSIWYG editor is in.

Similar to what filefield_sources has, where a image field can restrict IMCE to browse and upload only to that image's file directory.

I am not sure if this is possible, but I have looked everywhere and can't find anything. Any help would be great.

Comments

mr_kazoodle’s picture

Issue summary: View changes

subscribing

I would really like to have this functionality: my users cannot be trusted to know what to do.

nixar’s picture

subscribing

komlenic’s picture

In the IMCE directory settings, in addition to adding a string to specify a path, you can supply php code beginning with "php:". Whatever this code returns, will be the path used by IMCE - in this way you can set the directory per content-type (or many other conditions). In the case of a subdirectory for a given content type, something like this will work:

Assuming your content type is named "foo":

// detect when imce is being called during the creation of a new 'foo' page.
if (strpos($_SERVER['HTTP_REFERER'], 'node/add/foo') !== FALSE) {
  $path = 'foo';
}
// detect when imce is being called during the editing of a 'foo' page.
elseif (preg_match('/node\/edit\/([0-9]+)/', $_SERVER['HTTP_REFERER'], $matches)) {
  $node = node_load($matches[1]);
  if ($node->type == 'foo') {
    $path = 'foo';
  }
}
// some default condition for all other content types.
else {
  $path = '.';
}
return $path;

Of course, you'll need to preface that code above with the string "php: " and remove all the newlines.