These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | include __DIR__ . '/bootstrap.php'; |
||
3 | |||
4 | use Slince\Upload\UploadHandlerBuilder; |
||
5 | use Symfony\Component\HttpFoundation\File\UploadedFile; |
||
6 | |||
7 | $builder = new UploadHandlerBuilder(); |
||
8 | $handler = $builder |
||
9 | //Custom namer |
||
10 | ->naming(function (UploadedFile $file) { |
||
11 | return date('Y/md') . '/' . uniqid() . '.' . $file->getClientOriginalExtension(); |
||
12 | }) |
||
13 | |||
14 | //add constraints |
||
15 | ->sizeBetween('10m', '20m') |
||
16 | ->allowExtensions(['jpg', 'txt']) |
||
17 | ->allowMimeTypes(['image/*', 'text/plain']) |
||
18 | |||
19 | ->saveTo(__DIR__ . '/dst') |
||
20 | ->getHandler(); |
||
21 | |||
22 | $files = $handler->handle(); |
||
23 | |||
24 | foreach ($files as $file) { |
||
0 ignored issues
–
show
|
|||
25 | if ($file instanceof \Exception) { |
||
26 | echo 'upload error: ' . $file->getMessage(), PHP_EOL; |
||
27 | } else { |
||
28 | echo 'upload ok, path:' . $file->getPathname(); |
||
29 | } |
||
30 | } |
||
31 | |||
32 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.