Remove file_get / file_put combi for #193

This commit is contained in:
James Cole
2016-02-23 09:12:21 +01:00
parent 3f829a3114
commit a3bf30a77b

View File

@@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\MessageBag; use Illuminate\Support\MessageBag;
use Input; use Input;
use Log; use Log;
use Storage;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
use TypeError; use TypeError;
@@ -30,6 +31,9 @@ class AttachmentHelper implements AttachmentHelperInterface
/** @var int */ /** @var int */
protected $maxUploadSize; protected $maxUploadSize;
/** @var \Illuminate\Contracts\Filesystem\Filesystem */
protected $uploadDisk;
/** /**
* *
*/ */
@@ -39,6 +43,7 @@ class AttachmentHelper implements AttachmentHelperInterface
$this->allowedMimes = Config::get('firefly.allowedMimes'); $this->allowedMimes = Config::get('firefly.allowedMimes');
$this->errors = new MessageBag; $this->errors = new MessageBag;
$this->messages = new MessageBag; $this->messages = new MessageBag;
$this->uploadDisk = Storage::disk('upload');
} }
/** /**
@@ -148,15 +153,13 @@ class AttachmentHelper implements AttachmentHelperInterface
$attachment->uploaded = 0; $attachment->uploaded = 0;
$attachment->save(); $attachment->save();
$path = $file->getRealPath(); // encrypt and move file to storage. $fileObject = $file->openFile('r');
$content = file_get_contents($path); $fileObject->rewind();
$content = $fileObject->fread($file->getSize());
$encrypted = Crypt::encrypt($content); $encrypted = Crypt::encrypt($content);
// store it: // store it:
$upload = $this->getAttachmentLocation($attachment); $this->uploadDisk->put($attachment->fileName(), $encrypted);
if (is_writable(dirname($upload))) {
file_put_contents($upload, $encrypted);
}
$attachment->uploaded = 1; // update attachment $attachment->uploaded = 1; // update attachment
$attachment->save(); $attachment->save();