-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathMedia.php
More file actions
43 lines (38 loc) · 1.14 KB
/
Media.php
File metadata and controls
43 lines (38 loc) · 1.14 KB
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
38
39
40
41
42
43
<?php
namespace ProcessMaker;
use Illuminate\Http\File;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use ProcessMaker\Models\ProcessRequest;
use Spatie\MediaLibrary\FileManipulator;
use Spatie\MediaLibrary\Filesystem\Filesystem;
use Spatie\MediaLibrary\MediaCollections\Models\Media as BaseMedia;
class Media extends BaseMedia
{
/**
* Updates the Media with a new file
*
* @param UploadedFile $newFile
* @param Models\Media $file
*/
public function updateFile(UploadedFile $newFile, Models\Media $file)
{
$newFileName = $this->sanitizeFileName($newFile->getClientOriginalName());
$file->file_name = $newFileName;
$file->name = pathinfo($newFileName, PATHINFO_FILENAME);
$file->mime_type = $newFile->getMimeType();
$file->size = filesize($newFile->path());
$file->save();
}
/**
* Removes from file name non accepted characters
*
* @param string $fileName
*
* @return string
*/
protected function sanitizeFileName(string $fileName)
{
return str_replace(['#', '/', '\\'], '-', $fileName);
}
}