| @@ 119-150 (lines=32) @@ | ||
| 116 | * |
|
| 117 | * @throws \Exception If upload dir and path are not set |
|
| 118 | */ |
|
| 119 | public function imageUpload() |
|
| 120 | { |
|
| 121 | if (null !== $this->getImage()) { |
|
| 122 | $uploadDir = $this->getImageUploadDir(); |
|
| 123 | $uploadPath = $this->getImageUploadPath(); |
|
| 124 | ||
| 125 | if (!($uploadDir && $uploadPath)) { |
|
| 126 | throw new \Exception('You must define the image upload dir and path!'); |
|
| 127 | } |
|
| 128 | ||
| 129 | $slugify = new Slugify(); |
|
| 130 | ||
| 131 | $filename = $slugify->slugify( |
|
| 132 | $this->getImage()->getClientOriginalName() |
|
| 133 | ); |
|
| 134 | ||
| 135 | $filename .= '_'.sha1(uniqid(mt_rand(), true)).'.'. |
|
| 136 | $this->getImage()->guessExtension() |
|
| 137 | ; |
|
| 138 | ||
| 139 | $this->getImage()->move( |
|
| 140 | $uploadDir, |
|
| 141 | $filename |
|
| 142 | ); |
|
| 143 | ||
| 144 | $this->setImageUrl($uploadPath.$filename); |
|
| 145 | ||
| 146 | $this->setImage(null); |
|
| 147 | } |
|
| 148 | ||
| 149 | return $this; |
|
| 150 | } |
|
| 151 | } |
|
| 152 | ||
| @@ 282-313 (lines=32) @@ | ||
| 279 | * |
|
| 280 | * @throws \Exception If upload dir and path are not set |
|
| 281 | */ |
|
| 282 | public function imageUpload() |
|
| 283 | { |
|
| 284 | if (null !== $this->getImage()) { |
|
| 285 | $uploadDir = $this->getImageUploadDir(); |
|
| 286 | $uploadPath = $this->getImageUploadPath(); |
|
| 287 | ||
| 288 | if (!($uploadDir && $uploadPath)) { |
|
| 289 | throw new \Exception('You must define the image upload dir and path!'); |
|
| 290 | } |
|
| 291 | ||
| 292 | $slugify = new Slugify(); |
|
| 293 | ||
| 294 | $filename = $slugify->slugify( |
|
| 295 | $this->getImage()->getClientOriginalName() |
|
| 296 | ); |
|
| 297 | ||
| 298 | $filename .= '_'.sha1(uniqid(mt_rand(), true)).'.'. |
|
| 299 | $this->getImage()->guessExtension() |
|
| 300 | ; |
|
| 301 | ||
| 302 | $this->getImage()->move( |
|
| 303 | $uploadDir, |
|
| 304 | $filename |
|
| 305 | ); |
|
| 306 | ||
| 307 | $this->setImageUrl($uploadPath.$filename); |
|
| 308 | ||
| 309 | $this->setImage(null); |
|
| 310 | } |
|
| 311 | ||
| 312 | return $this; |
|
| 313 | } |
|
| 314 | ||
| 315 | /*** User ***/ |
|
| 316 | /** |
|