Moodle ZIP error fix for Windows using UNC Paths

Apologies for the confusing blog title, I did this so that other users with the same problem could find it easily in Google.

The problem:
We recently moved our Moodle installation onto separate Windows servers.  The MoodleData folder now resides on a separate box to the webserver.  Everything was great until we tried to use any of the ZIP features in Moodle.  Course restore, course backups, SCORM Packages etc… simply would not work.  After spending long days and late evenings trawling through the Moodle libraries and searching the forums I managed to find a fix, courtesy of Kiran Dhaman.

The Fix:
Easy once you know how.

In congif.php, make sure you put 4 backslashes in the UNC path to the MoodleData folder,
For example:

$CFG->dataroot  = '\\\\pathtoserver\moodledata';

 

Now edit lib/moodle.lib

Find this code:

function cleardoubleslashes ($path) {
    return preg_replace('/(\/|\\\){1,}/','/',$path);
}

And replace with this code:

function cleardoubleslashes ($path) {

if (substr($path, 0, 2) == "\\\\" or substr($path, 0, 2) == "//")
return $path;
else
return preg_replace('/(\/|\\\){1,}/','/',$path);

 

And now the ZIP functions work again!  This is only an issue with Windows Server setups, and Petr ┼ákoda has stated that there can’t be an official fix as this is a PHP limitation but has hinted it may be resolved in Moodle 2.0.

 

Comments are closed.