Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit f3036dc

Browse files
committed
[#82] Ensure moveTo() works in non-SAPI environments
- Updates `writeFile()` to call `getStream()` instead of assuming `$stream` is already populated correctly; this ensures that if a filename, and not a stream or resource, was provided to the constructor, the file can still be correctly moved.
1 parent e654167 commit f3036dc

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/UploadedFile.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ private function writeFile($path)
223223
throw new RuntimeException('Unable to write to designated path');
224224
}
225225

226-
$this->stream->rewind();
227-
while (! $this->stream->eof()) {
228-
fwrite($handle, $this->stream->read(4096));
226+
$stream = $this->getStream();
227+
$stream->rewind();
228+
while (! $stream->eof()) {
229+
fwrite($handle, $stream->read(4096));
229230
}
230231

231232
fclose($handle);

test/UploadedFileTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,20 @@ public function testGetStreamRaisesExceptionWhenErrorStatusPresent($status)
270270
$this->setExpectedException('RuntimeException', 'upload error');
271271
$stream = $uploadedFile->getStream();
272272
}
273+
274+
/**
275+
* @group 82
276+
*/
277+
public function testMoveToCreatesStreamIfOnlyAFilenameWasProvided()
278+
{
279+
$this->tmpFile = tempnam(sys_get_temp_dir(), 'DIA');
280+
281+
$uploadedFile = new UploadedFile(__FILE__, 100, UPLOAD_ERR_OK, basename(__FILE__), 'text/plain');
282+
$uploadedFile->moveTo($this->tmpFile);
283+
284+
$original = file_get_contents(__FILE__);
285+
$test = file_get_contents($this->tmpFile);
286+
287+
$this->assertEquals($original, $test);
288+
}
273289
}

0 commit comments

Comments
 (0)