diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 35df7181af7..7138f03c0d5 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -5858,9 +5858,14 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '', $attachmentpath = $attachment; + // Before doing the comparison, make sure that the paths are correct (Windows uses slashes in the other direction). + $attachpath = str_replace('\\', '/', $attachmentpath); + // Make sure both variables are normalised before comparing. + $temppath = str_replace('\\', '/', $CFG->tempdir); + // If the attachment is a full path to a file in the tempdir, use it as is, // otherwise assume it is a relative path from the dataroot (for backwards compatibility reasons). - if (strpos($attachmentpath, $CFG->tempdir) !== 0) { + if (strpos($attachpath, $temppath) !== 0) { $attachmentpath = $CFG->dataroot . '/' . $attachmentpath; }