1
0
mirror of https://github.com/flarum/core.git synced 2025-08-03 15:07:53 +02:00

Remove temporary file after avatar upload failure. closes flarum/core#999

This commit is contained in:
Toby Zerner
2016-08-27 23:53:02 +09:30
parent 883e1188b4
commit b7586e819b

View File

@@ -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;
}
}
}