diff --git a/src/League/Flysystem/Adapter/Local.php b/src/League/Flysystem/Adapter/Local.php index c36907e06..f7c5f31c8 100644 --- a/src/League/Flysystem/Adapter/Local.php +++ b/src/League/Flysystem/Adapter/Local.php @@ -121,8 +121,13 @@ public function writeStream($path, $resource, $config = null) { rewind($resource); $config = Util::ensureConfig($config); + $location = $this->prefix($path); - if ( ! $stream = fopen($this->prefix($path), 'w+')) { + if ( ! is_dir($dirname = dirname($location))) { + mkdir($dirname, 0777, true); + } + + if ( ! $stream = fopen($location, 'w+')) { return false; } @@ -134,8 +139,9 @@ public function writeStream($path, $resource, $config = null) return false; } - if ($visibility = $config->get('visibility')) + if ($visibility = $config->get('visibility')) { $this->setVisibility($path, $visibility); + } return compact('path', 'visibility'); } diff --git a/tests/LocalAdapterTests.php b/tests/LocalAdapterTests.php index a7cf2160c..14bb05f21 100644 --- a/tests/LocalAdapterTests.php +++ b/tests/LocalAdapterTests.php @@ -57,12 +57,12 @@ public function testWriteStream() $temp = tmpfile(); fwrite($temp, 'dummy'); rewind($temp); - $adapter->writeStream('file.txt', $temp); + $adapter->writeStream('dir/file.txt', $temp); fclose($temp); - $this->assertTrue($adapter->has('file.txt')); - $result = $adapter->read('file.txt'); + $this->assertTrue($adapter->has('dir/file.txt')); + $result = $adapter->read('dir/file.txt'); $this->assertEquals('dummy', $result['contents']); - $adapter->delete('file.txt'); + $adapter->delete('dir/file.txt'); } public function testUpdateStream()