Upload Files Booking, Mails, Attachments,
This commit is contained in:
parent
5daea268f7
commit
68b9d1ff88
92 changed files with 2837 additions and 1778 deletions
108
app/Repositories/FileRepository.php
Normal file
108
app/Repositories/FileRepository.php
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Response;
|
||||
use Storage;
|
||||
use Util;
|
||||
use Validator;
|
||||
|
||||
class FileRepository extends BaseRepository {
|
||||
|
||||
|
||||
protected $rules;
|
||||
protected $messages;
|
||||
|
||||
protected $disk;
|
||||
protected $dir;
|
||||
|
||||
protected $filename;
|
||||
protected $allowed_filename;
|
||||
protected $originalName;
|
||||
protected $extension;
|
||||
protected $mine;
|
||||
protected $size;
|
||||
|
||||
|
||||
public function __construct(){
|
||||
|
||||
$this->rules = [
|
||||
'file' => 'required|mimes:pdf,jpeg,png|max:32768'
|
||||
];
|
||||
$this->messages = [
|
||||
'file.mimes' => 'Datei ist kein PDF/JPG/PNG Format',
|
||||
'file.required' => 'PDF/JPG/PNG-Datei wird benötigt'
|
||||
];
|
||||
}
|
||||
|
||||
public function _set($name, $value){
|
||||
$this->{$name} = $value;
|
||||
}
|
||||
|
||||
public function uploadFile( $form_data )
|
||||
{
|
||||
$validator = Validator::make($form_data, $this->rules, $this->messages);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return Response::json([
|
||||
'error' => true,
|
||||
'message' => $validator->messages()->first(),
|
||||
'code' => 400
|
||||
], 400);
|
||||
}
|
||||
$file = $form_data['file'];
|
||||
|
||||
$this->originalName = $file->getClientOriginalName();
|
||||
$this->extension = strtolower($file->getClientOriginalExtension());
|
||||
$this->mine = $file->getClientMimeType();
|
||||
$this->size = $file->getClientSize();
|
||||
|
||||
|
||||
$this->makeFilename();
|
||||
//$dir = $this->model->getInvoiceStorageAttDir();
|
||||
|
||||
$this->store(file_get_contents($file->getRealPath()));
|
||||
$this->save();
|
||||
return $this->response();
|
||||
|
||||
}
|
||||
|
||||
public function storeFile( $content )
|
||||
{
|
||||
$this->makeFilename();
|
||||
$this->store($content);
|
||||
$this->size = Storage::disk($this->disk)->size($this->dir.$this->allowed_filename);
|
||||
$this->save();
|
||||
return $this->response();
|
||||
}
|
||||
|
||||
public function store($content){
|
||||
if(!Storage::disk($this->disk)->exists( $this->dir )){
|
||||
Storage::disk($this->disk)->makeDirectory($this->dir); //creates directory
|
||||
}
|
||||
Storage::disk($this->disk)->put($this->dir.$this->allowed_filename, $content);
|
||||
}
|
||||
|
||||
public function save(){
|
||||
|
||||
}
|
||||
|
||||
public function response(){
|
||||
return Response::json([
|
||||
'error' => false,
|
||||
'filename' => $this->allowed_filename,
|
||||
'originalName' => $this->originalName,
|
||||
'file_data' => $this->extension,
|
||||
'mine' => $this->mine,
|
||||
'size' => $this->size,
|
||||
'redirect' => '',
|
||||
'code' => 200
|
||||
], 200);
|
||||
}
|
||||
|
||||
private function makeFilename(){
|
||||
$originalNameWithoutExt = substr($this->originalName, 0, strlen($this->originalName) - strlen($this->extension) - 1);
|
||||
$this->filename = Util::sanitize($originalNameWithoutExt, true, false, true);
|
||||
$this->allowed_filename = uniqid("", true) . '_' . $this->filename.".".$this->extension;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue