I have saved a file with this command
$newFile = [ 'event_id' => $event->id, 'path' => $storePath ]; EventFile::create($newFile);
I can get the path to the file for a link like this:
Storage::disk('public')->url($file->path);
But there is no data about the file size. How can i get the file size in blade view???
Route::post('/files/add', 'FilesController@store')->name('files. store'); Then in your controller let's create a store method. Then that's it you will know if what is the byte size of your file and convert it to MB or KB.
Laravel's filesystem configuration file is located at config/filesystems.php . Within this file, you may configure all of your filesystem "disks". Each disk represents a particular storage driver and storage location.
The hashName method is exactly what Laravel calls in the store method. $request->image->hashName(); You will get the same name that Laravel generates when it creates the file name during the store method. $path = $request->image->getClientOriginalName();
Laravel 5^
$request->file('file')->getSize();
Laravel 4
$request->file('file')->getClientSize(); // getClientSize() is deprecated in Laravel 5
The more Simpler way is to use Storage Facade
if you have already stored / uploaded file
use Illuminate\Support\Facades\Storage; public function get_size($file_path) { return Storage::size($file_path); }
Or if you are using S3
Bucket then you can modify the above function like below
use Illuminate\Support\Facades\Storage; public function get_size($file_path) { return Storage::disk('s3')->size($file_path); }
Check Laravel File Storage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With