mirror of
https://github.com/flarum/framework.git
synced 2025-06-03 22:43:10 +08:00
Remove temporary file after avatar upload failure. closes flarum/core#999
This commit is contained in:
@ -10,6 +10,7 @@
|
||||
|
||||
namespace Flarum\Core\Command;
|
||||
|
||||
use Exception;
|
||||
use Flarum\Core\Access\AssertPermissionTrait;
|
||||
use Flarum\Core\Repository\UserRepository;
|
||||
use Flarum\Core\Support\DispatchEventsTrait;
|
||||
@ -84,6 +85,7 @@ class UploadAvatarHandler
|
||||
$tmpFile = tempnam($this->app->storagePath().'/tmp', 'avatar');
|
||||
$command->file->moveTo($tmpFile);
|
||||
|
||||
try {
|
||||
$file = new UploadedFile(
|
||||
$tmpFile,
|
||||
$command->file->getClientFilename(),
|
||||
@ -125,5 +127,10 @@ class UploadAvatarHandler
|
||||
$this->dispatchEventsFor($user, $actor);
|
||||
|
||||
return $user;
|
||||
} catch (Exception $e) {
|
||||
@unlink($tmpFile);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user