Skip to content

Commit

Permalink
Fix file upload in Symfony v5
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieudz committed May 2, 2020
1 parent e060e0b commit 9039647
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions Bridges/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,27 @@ private function mapFiles(&$files)
if (UPLOAD_ERR_OK == $file->getError()) {
file_put_contents($tmpname, (string)$file->getStream());
}
$file = new SymfonyFile(
$tmpname,
$file->getClientFilename(),
$file->getClientMediaType(),
$file->getSize(),
$file->getError(),
true
);
$class = new \ReflectionClass('Symfony\Component\HttpFoundation\File\UploadedFile');
if (count($class->getConstructor()->getParameters()) === 5) {
// Symfony < v4.1
$file = new SymfonyFile(
$tmpname,
$file->getClientFilename(),
$file->getClientMediaType(),
$file->getSize(),
$file->getError(),
true
);
} else {
$file = new SymfonyFile(
$tmpname,
$file->getClientFilename(),
$file->getClientMediaType(),
$file->getError(),
true
);
}

}
}
}
Expand Down

0 comments on commit 9039647

Please sign in to comment.