After updating a perfectly working system from 6.x-2.2 to 6.x-2.3 we get:

Unable to get a working directory for the file browser!

Module imce.page.inc is producing this erroneous error with:

function imce_check_directory($dirname, $imce = array()) {

  if (!imce_reg_dir($dirname)) {
    // HD: added this debug code:
    watchdog('imce', 'HD: Directory %directory considered inaccessible!', array('%directory' => $dirname), WATCHDOG_ERROR);
    // We get in here !? Why? This piece of code is new with version 2.3.
    // All our directories ARE accessible and writable and IMCE has been working just fine with version 2.2.
    // When I comment out the "return command" below, IMCE is working as before the 2.2 to 2.3 update.
    //return imce_inaccessible_directory($dirname, $imce);
  }
  .......

In the Drupal logs I now get for example: "HD: Directory 705 considered inaccessible!"
705 is a uid. All directories are named like that, there is nothing wrong with that.

What is function imce_reg_dir() doing as defined in imce.module? It is same as with version 2.2.

/**
 * Check if the directory name is regular.
 */
function imce_reg_dir($dirname) {
  return $dirname == '.' || (is_string($dirname) && $dirname != '' && !preg_match('@(^\s)|(^/)|(^\./)|(\s$)|(/$)|(/\.$)|(\.\.)|(//)|(\\\\)|(/\./)@', $dirname));
}

The problem is that imce_reg_dir() returns FALSE for a directory named eg 705 because of is_string($dirname). It returns TRUE for a directory named eg paul.

Well, our directory names are like 705, which are uids, and are working well with version 2.2

Comments

hd’s picture

Issue summary: View changes

Fixed a type in "What is function imce_reg_dir() doing as defined in imce.module? "

ufku’s picture

The latest changes were made to overcome the core bug: #200586: file_check_location and non-existing directories

IMCE's new bug seems to be a result of foreach($arr as $key=>$val) converting numeric string keys into integer. And any integer fails in imce_reg_dir.

This should work.

function imce_reg_dir($dirname) {
  return $dirname == '.' || is_int($dirname) || (is_string($dirname) && $dirname != '' && !preg_match('@(^\s)|(^/)|(^\./)|(\s$)|(/$)|(/\.$)|(\.\.)|(//)|(\\\\)|(/\./)@', $dirname));
}

I'll investigate this further and commit a fix soon.

ufku’s picture

Version: 6.x-2.3 » 6.x-2.x-dev
Status: Active » Fixed

Committed. Thanks.

hd’s picture

Installed the 6.x-2.x-dev version from 2011-Oct-31 and it fixed the problem.
Thanks for the quick response.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sekhar.anup’s picture

It is working fine in Windows OS but for the same task it is throwing this error in MAC OS. Could some one help on resolving this issue please?

Thanks,
Sekhar.

sekhar.anup’s picture

Issue summary: View changes

Added " because of is_string($dirname)" in sentence "The problem is that imce_reg_dir() returns FALSE for a directory named eg 705 because of is_string($dirname). It returns TRUE for a directory named eg paul."