Skip to content

Commit 4ca38b9

Browse files
eldarioEldariotaylorotwell
authored
Fix FlushUploadedFiles listener (laravel#1044)
* Fix FlushUploadedFiles listener * formatting --------- Co-authored-by: Eldario <mardanov.e@spectrumdata.ru> Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 19a2c44 commit 4ca38b9

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/Listeners/FlushUploadedFiles.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Laravel\Octane\Listeners;
44

5+
use Illuminate\Support\Arr;
56
use SplFileInfo;
67

78
class FlushUploadedFiles
@@ -13,16 +14,18 @@ class FlushUploadedFiles
1314
*/
1415
public function handle($event): void
1516
{
16-
foreach ($event->request->files->all() as $file) {
17-
if (! $file instanceof SplFileInfo ||
18-
! is_string($path = $file->getRealPath())) {
19-
continue;
20-
}
17+
foreach ($event->request->files->all() as $files) {
18+
foreach (Arr::wrap($files) as $file) {
19+
if (! $file instanceof SplFileInfo ||
20+
! is_string($path = $file->getRealPath())) {
21+
continue;
22+
}
2123

22-
clearstatcache(true, $path);
24+
clearstatcache(true, $path);
2325

24-
if (is_file($path)) {
25-
unlink($path);
26+
if (is_file($path)) {
27+
unlink($path);
28+
}
2629
}
2730
}
2831
}

tests/Listeners/FlushUploadedFilesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public function test_files_removed()
2222
];
2323

2424
($request = Request::create('http://127.0.0.1:123/foo'))->files->add([
25-
new UploadedFile($file1path, Str::random()),
26-
new UploadedFile($file2path, Str::random()),
25+
[new UploadedFile($file1path, Str::random())],
26+
[new UploadedFile($file2path, Str::random())],
2727
new UploadedFile($file3path, Str::random()),
2828
]);
2929

0 commit comments

Comments
 (0)