// Normalize paths to compare them.
$filepath = realpath($this->name); // File path comes in name.
$filename = basename($filepath);
- $structurepath = realpath($CFG->dirroot . DIRECTORY_SEPARATOR . $this->path . DIRECTORY_SEPARATOR . $filename);
+ $normalisedpath = $this->path;
+ if ($CFG->admin !== 'admin') {
+ $needle = 'admin/';
+ if (strpos($this->path, $needle) === 0) {
+ $normalisedpath = substr_replace($this->path, "$CFG->admin/", 0, strlen($needle));
+ }
+ }
+ $structurepath = realpath($CFG->dirroot . DIRECTORY_SEPARATOR . $normalisedpath . DIRECTORY_SEPARATOR . $filename);
if ($filepath !== $structurepath) {
$relativepath = dirname(str_replace(realpath($CFG->dirroot) . DIRECTORY_SEPARATOR, '', $filepath));
$this->errormsg = 'PATH attribute does not match file directory: ' . $relativepath;