From a3bf30a77b29afef598b618bf9d78bf9a636beb9 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 23 Feb 2016 09:12:21 +0100 Subject: [PATCH] Remove file_get / file_put combi for #193 --- app/Helpers/Attachments/AttachmentHelper.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/Helpers/Attachments/AttachmentHelper.php b/app/Helpers/Attachments/AttachmentHelper.php index 08e9086af4..d23e74b35f 100644 --- a/app/Helpers/Attachments/AttachmentHelper.php +++ b/app/Helpers/Attachments/AttachmentHelper.php @@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\MessageBag; use Input; use Log; +use Storage; use Symfony\Component\HttpFoundation\File\UploadedFile; use TypeError; @@ -30,6 +31,9 @@ class AttachmentHelper implements AttachmentHelperInterface /** @var int */ protected $maxUploadSize; + /** @var \Illuminate\Contracts\Filesystem\Filesystem */ + protected $uploadDisk; + /** * */ @@ -39,6 +43,7 @@ class AttachmentHelper implements AttachmentHelperInterface $this->allowedMimes = Config::get('firefly.allowedMimes'); $this->errors = new MessageBag; $this->messages = new MessageBag; + $this->uploadDisk = Storage::disk('upload'); } /** @@ -148,15 +153,13 @@ class AttachmentHelper implements AttachmentHelperInterface $attachment->uploaded = 0; $attachment->save(); - $path = $file->getRealPath(); // encrypt and move file to storage. - $content = file_get_contents($path); + $fileObject = $file->openFile('r'); + $fileObject->rewind(); + $content = $fileObject->fread($file->getSize()); $encrypted = Crypt::encrypt($content); // store it: - $upload = $this->getAttachmentLocation($attachment); - if (is_writable(dirname($upload))) { - file_put_contents($upload, $encrypted); - } + $this->uploadDisk->put($attachment->fileName(), $encrypted); $attachment->uploaded = 1; // update attachment $attachment->save();