Skip to content

Commit 53e9b2e

Browse files
committed
fix delete the old image before the move of new image because of the same name
1 parent 8b8d35c commit 53e9b2e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

cookbook/doctrine/file_uploads.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,14 @@ property, instead of the actual filename::
443443
return;
444444
}
445445

446+
// check if we have an old image
447+
if (isset($this->temp)) {
448+
// delete the old image
449+
unlink($this->temp);
450+
// clear the temp image path
451+
$this->temp = null;
452+
}
453+
446454
// you must throw an exception here if the file cannot be moved
447455
// so that the entity is not persisted to the database
448456
// which the UploadedFile move() method does
@@ -452,14 +460,6 @@ property, instead of the actual filename::
452460
);
453461

454462
unset($this->file);
455-
456-
// check if we have an old image
457-
if (isset($this->temp)) {
458-
// delete the old image
459-
unlink($this->temp);
460-
// clear the temp image path
461-
$this->temp = null;
462-
}
463463
}
464464

465465
/**

0 commit comments

Comments
 (0)