diff --git includes/stream_wrappers.inc includes/stream_wrappers.inc
index 75a1f8f..c721f44 100644
--- includes/stream_wrappers.inc
+++ includes/stream_wrappers.inc
@@ -438,13 +438,20 @@ abstract class DrupalLocalStreamWrapper implements DrupalStreamWrapperInterface
    * @see http://php.net/manual/en/streamwrapper.mkdir.php
    */
   public function mkdir($uri, $mode, $options) {
-    $this->uri = $uri;
     $recursive = (bool)($options & STREAM_MKDIR_RECURSIVE);
+    if ($recursive) {
+      // $this->getLocalPath() fails if $uri has multiple levels of directories
+      // that do not yet exist.
+      $localpath = $this->getDirectoryPath() . '/' . file_uri_target($uri);
+    }
+    else {
+      $localpath = $this->getLocalPath($uri);
+    }
     if ($options & STREAM_REPORT_ERRORS) {
-      return mkdir($this->getLocalPath(), $mode, $recursive);
+      return mkdir($localpath, $mode, $recursive);
     }
     else {
-      return @mkdir($this->getLocalPath(), $mode, $recursive);
+      return @mkdir($localpath, $mode, $recursive);
     }
   }
 
