UniSharp / laravel-filemanager

Media gallery with CKEditor, TinyMCE and Summernote support. Built on Laravel file system.
https://unisharp.github.io/laravel-filemanager/
MIT License
2.09k stars 720 forks source link

How Can I Get File Properties Like File Size, File Name? #1158

Closed reasecret closed 2 years ago

reasecret commented 2 years ago

I'm trying to save image data to database. But don't know how to get file size, file extension and file name on my event listener. I can get only file path. Anyone tried something like this?

reasecret commented 2 years ago

Solved.

foreach (request('upload') as $key => $item) {
            $publicFilePath = str_replace(storage_path(), "", $event->path());
            File::create([
                'file_mime_type' => $item->getMimeType(),
                'file_extension' => $item->getClientOriginalExtension(),
                'file_original_name' => $item->getClientOriginalName(),
                'file_size' => $item->getSize(),
                'file_path' => $publicFilePath,
            ]);
        }