Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel filesize of a filethat is uploaded to Storage folder

Tags:

php

laravel

How can i get the file size of a file stored in the storage folder? $fileFullPath leads to correct path but $size = Storage::size($fileFullPath) fires the exception: File not found at path.

public function getFromStorage()
{
  $contents = Storage::disk('local')->get('txtFiles/file.txt');
  $fileFullPath = Storage::disk('local')->path('txtFiles/file.txt');
  $size = Storage::size($fileFullPath);
  dd( $fileFullPath) // return correct path
  dd( $size) // return file not found
 }
like image 459
Eskander One Avatar asked Dec 08 '25 09:12

Eskander One


1 Answers

size($file) does not expect the full path, but the relative path. Try:

$size = Storage::disk('local')->size('txtFiles/file.txt');
like image 90
gbalduzzi Avatar answered Dec 10 '25 22:12

gbalduzzi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!