Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,24 +142,26 @@ public function getStream()
*/
public function moveTo($targetPath)
{
if ($this->error !== UPLOAD_ERR_OK) {
throw new RuntimeException('Cannot retrieve stream due to upload error');
if ($this->moved) {
throw new RuntimeException('Cannot move file; already moved!');
}

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

if (empty($targetPath)) {
if (! is_string($targetPath) || empty($targetPath)) {
throw new InvalidArgumentException(
'Invalid path provided for move operation; must be a non-empty string'
);
}

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

$sapi = PHP_SAPI;
Expand Down