From de3f9d82a0e974146133df162e1ad333b49e6807 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 19 Jun 2015 16:26:16 +0930 Subject: [PATCH] Update avatar uploading code for psr-7 Not sure if a tmp file is the best way, but it works --- .../core/src/Core/Commands/UploadAvatarCommand.php | 5 +++-- .../Handlers/Commands/UploadAvatarCommandHandler.php | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/framework/core/src/Core/Commands/UploadAvatarCommand.php b/framework/core/src/Core/Commands/UploadAvatarCommand.php index acbd8aaef..a5da11db3 100644 --- a/framework/core/src/Core/Commands/UploadAvatarCommand.php +++ b/framework/core/src/Core/Commands/UploadAvatarCommand.php @@ -1,5 +1,6 @@ assertCan($command->actor, 'edit'); - $manager = new ImageManager(array('driver' => 'imagick')); - $manager->make($command->file->getRealPath())->fit(100, 100)->save(); + $tmpFile = tempnam(sys_get_temp_dir(), 'avatar'); + $command->file->moveTo($tmpFile); - $filename = $command->file->getFilename(); $uploadName = Str::lower(Str::quickRandom()) . '.jpg'; + $manager = new ImageManager(array('driver' => 'imagick')); + $manager->make($tmpFile)->fit(100, 100)->save(); + $mount = new MountManager([ - 'source' => new Filesystem(new Local($command->file->getPath())), + 'source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => $this->uploadDir, ]); @@ -59,7 +61,7 @@ class UploadAvatarCommandHandler event(new AvatarWillBeUploaded($user, $command)); - $mount->move("source://$filename", "target://$uploadName"); + $mount->move("source://".pathinfo($tmpFile, PATHINFO_BASENAME), "target://$uploadName"); $user->save(); $this->dispatchEventsFor($user);