Conditions | 5 |
Paths | 3 |
Total Lines | 23 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | public function upload(ImageInterface $image) |
||
21 | { |
||
22 | if (!$image->hasFile()) { |
||
23 | return; |
||
24 | } |
||
25 | |||
26 | // remove older path |
||
27 | if (null !== $image->getPath() && $this->filesystem->has($image->getPath())) { |
||
28 | $this->remove($image->getPath()); |
||
29 | } |
||
30 | |||
31 | do { |
||
32 | $hash = md5(uniqid(mt_rand(), true)); |
||
33 | $path = $this->expandPath($hash.'.'.$image->getFile()->getExtension()); |
||
34 | } while ($this->filesystem->has($path)); |
||
35 | |||
36 | $image->setPath($path); |
||
37 | |||
38 | $this->filesystem->write( |
||
39 | $image->getPath(), |
||
40 | file_get_contents($image->getFile()->getPathname()) |
||
41 | ); |
||
42 | } |
||
43 | |||
69 |