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

Commit f8be6f3

Browse files
committed
Merge branch 'hotfix/179'
Close #179
2 parents dfd6c6e + d4911dd commit f8be6f3

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/UploadedFile.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,26 @@ public function getStream()
142142
*/
143143
public function moveTo($targetPath)
144144
{
145-
if ($this->error !== UPLOAD_ERR_OK) {
146-
throw new RuntimeException('Cannot retrieve stream due to upload error');
145+
if ($this->moved) {
146+
throw new RuntimeException('Cannot move file; already moved!');
147147
}
148148

149-
if (! is_string($targetPath)) {
150-
throw new InvalidArgumentException(
151-
'Invalid path provided for move operation; must be a string'
152-
);
149+
if ($this->error !== UPLOAD_ERR_OK) {
150+
throw new RuntimeException('Cannot retrieve stream due to upload error');
153151
}
154152

155-
if (empty($targetPath)) {
153+
if (! is_string($targetPath) || empty($targetPath)) {
156154
throw new InvalidArgumentException(
157155
'Invalid path provided for move operation; must be a non-empty string'
158156
);
159157
}
160158

161-
if ($this->moved) {
162-
throw new RuntimeException('Cannot move file; already moved!');
159+
$targetDirectory = dirname($targetPath);
160+
if (! is_dir($targetDirectory) || ! is_writable($targetDirectory)) {
161+
throw new RuntimeException(sprintf(
162+
'The target directory `%s` does not exists or is not writable',
163+
$targetDirectory
164+
));
163165
}
164166

165167
$sapi = PHP_SAPI;

0 commit comments

Comments
 (0)