55use Image ;
66use Storage ;
77use Illuminate \Support \Str ;
8- use Illuminate \Http \UploadedFile ;
98
109class Uploader
1110{
1211 /**
1312 * Put the file into the storage.
1413 *
1514 * @param string $directory
16- * @param Illuminate\Http\UploadedFile $file
15+ * @param mixed $file
1716 *
1817 * @return array
1918 */
20- public static function upload (string $ directory , UploadedFile $ file )
19+ public static function upload (string $ directory , $ file )
2120 {
2221 $ disk = config ('filesystems.default ' );
2322 $ filename = str_random (64 ).'. ' .$ file ->getClientOriginalExtension ();
2423 $ original_filename = $ file ->getClientOriginalName ();
24+ $ filesize = $ file ->getSize ();
25+ $ thumbnail_filesize = null ;
2526
2627 // Upload the file
2728 $ path = Storage::putFileAs ($ directory , $ file , $ filename );
@@ -42,15 +43,38 @@ public static function upload(string $directory, UploadedFile $file)
4243 $ fullThumbnailPath =
4344 "{$ fileSystemRoot }/ {$ thumbnailDirectory }/ {$ filename }" ;
4445
45- Image::make ($ fullPath )
46+ $ image = Image::make ($ fullPath )
4647 ->fit (240 )
4748 ->save ($ fullThumbnailPath , 95 );
4849
50+ $ thumbnail_filesize = Storage::size ($ thumbnailPath );
4951 $ thumbnail_url = Storage::url ($ thumbnailPath );
5052 }
5153
5254 return compact ([
53- 'directory ' , 'filename ' , 'original_filename ' , 'url ' , 'thumbnail_url '
55+ 'directory ' ,
56+ 'filename ' ,
57+ 'original_filename ' ,
58+ 'filesize ' ,
59+ 'thumbnail_filesize ' ,
60+ 'url ' ,
61+ 'thumbnail_url '
5462 ]);
5563 }
64+
65+ /**
66+ * Destroy files from disk.
67+ *
68+ * @param array $upload
69+ *
70+ * @return bool
71+ */
72+ public static function destroy (array $ upload )
73+ {
74+ $ path = "{$ upload ['directory ' ]}/ {$ upload ['filename ' ]}" ;
75+ $ thumbnailPath =
76+ "{$ upload ['directory ' ]}/thumbnails/ {$ upload ['filename ' ]}" ;
77+
78+ return Storage::delete ([$ path , $ thumbnailPath ]);
79+ }
5680}
0 commit comments