Skip to content

Commit 464d0cc

Browse files
committed
Merge pull request thephpleague#495 from twistor/ftp-fclose-write
Don't depend on fclose() of temp stream for return value to write() in Ftp adapter.
2 parents 3ade784 + 4af1d72 commit 464d0cc

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/Adapter/Ftp.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,22 @@ public function disconnect()
151151
*/
152152
public function write($path, $contents, Config $config)
153153
{
154-
$mimetype = Util::guessMimeType($path, $contents);
155-
$config = Util::ensureConfig($config);
156-
$stream = tmpfile();
154+
$stream = fopen('php://temp', 'w+b');
157155
fwrite($stream, $contents);
158156
rewind($stream);
157+
159158
$result = $this->writeStream($path, $stream, $config);
160-
$result = fclose($stream) && $result;
159+
160+
fclose($stream);
161161

162162
if ($result === false) {
163163
return false;
164164
}
165165

166-
if ($visibility = $config->get('visibility')) {
167-
$this->setVisibility($path, $visibility);
168-
}
166+
$result['contents'] = $contents;
167+
$result['mimetype'] = Util::guessMimeType($path, $contents);
169168

170-
return compact('path', 'contents', 'mimetype', 'visibility');
169+
return $result;
171170
}
172171

173172
/**
@@ -176,7 +175,6 @@ public function write($path, $contents, Config $config)
176175
public function writeStream($path, $resource, Config $config)
177176
{
178177
$this->ensureDirectory(Util::dirname($path));
179-
$config = Util::ensureConfig($config);
180178

181179
if (! ftp_fput($this->getConnection(), $path, $resource, $this->transferMode)) {
182180
return false;

src/Adapter/NullAdapter.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use League\Flysystem\Adapter\Polyfill\StreamedCopyTrait;
66
use League\Flysystem\Adapter\Polyfill\StreamedTrait;
77
use League\Flysystem\Config;
8-
use League\Flysystem\Util;
98

109
class NullAdapter extends AbstractAdapter
1110
{
@@ -30,7 +29,6 @@ public function has($path)
3029
public function write($path, $contents, Config $config)
3130
{
3231
$type = 'file';
33-
$config = Util::ensureConfig($config);
3432
$result = compact('contents', 'type', 'size', 'path');
3533

3634
if ($visibility = $config->get('visibility')) {

tests/UtilMimeTests.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ public function testNoFinfoFallback()
2424
$this->assertNull(MimeType::detectByContent('string'));
2525
$passthru = true;
2626
}
27+
28+
public function testNoExtension()
29+
{
30+
$this->assertNull(MimeType::detectByFileExtension(''));
31+
}
2732
}

0 commit comments

Comments
 (0)