Skip to content

Commit d015048

Browse files
rumours86xabbuh
authored andcommitted
Update upload_file.rst
1 parent 581bebb commit d015048

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

controller/upload_file.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ automatically upload the file when persisting the entity::
332332
class BrochureUploadListener
333333
{
334334
private $uploader;
335+
private $fileName;
335336

336337
public function __construct(FileUploader $uploader)
337338
{
@@ -362,11 +363,10 @@ automatically upload the file when persisting the entity::
362363
$file = $entity->getBrochure();
363364

364365
// only upload new files
365-
if (!$file instanceof UploadedFile) {
366-
return;
366+
if ($file instanceof UploadedFile) {
367+
$fileName = $this->uploader->upload($file);
367368
}
368369

369-
$fileName = $this->uploader->upload($file);
370370
$entity->setBrochure($fileName);
371371
}
372372
}
@@ -449,8 +449,9 @@ controller.
449449
return;
450450
}
451451

452-
if ($fileName = $entity->getBrochure()) {
453-
$entity->setBrochure(new File($this->uploader->getTargetDir().'/'.$fileName));
452+
$this->fileName = $entity->getBrochure()
453+
if ($this->fileName) {
454+
$entity->setBrochure(new File($this->uploader->getTargetDir().'/'.$this->fileName));
454455
}
455456
}
456457
}

0 commit comments

Comments
 (0)