1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace Yjtec\Upload\Models;
use Illuminate\Database\Eloquent\Model;
class File extends Model
{
//
protected $table = "file_system_v2";
protected $fillable = [
'filename', 'mimetype', 'filesize', 'extension', 'path', 'url', 'foreign_key', 'type',
];
public function getUrlAttribute()
{
$path = $this->attributes['path'];
if (config('filesystems.oss_host', '') == '') {
return \Storage::url($path);
} else {
return config('filesystems.oss_host', '') . $path;
}
}
public function setFileAttribute($file)
{
$this->attributes['filename'] = $file->getClientOriginalName();
$this->attributes['mimetype'] = $file->getClientMimeType();
$this->attributes['filesize'] = $file->getClientSize();
$this->attributes['extension'] = $file->guessClientExtension();
}
public function setPathAttribute($path)
{
$this->attributes['key'] = md5($path);
$this->attributes['path'] = $path;
}
}