Chris
Chris

Reputation: 2181

Laravel filesize of a pictures that is uploaded

I want to output the filesize of an image that is stored in this location:

storage/app/public/filename.jpg

When I do this:

filesize(public_path($picture->filename));

I get the following error:

filesize(): stat failed for agrant/Code/public/public/H0afvcjKJN3ecEUAf8qx6VlRFqDuVDOkOGwnfY3y.jpeg

Upvotes: 1

Views: 6520

Answers (2)

Rahman Rezaee
Rahman Rezaee

Reputation: 2165

This code get your size of file in that you already stored use File;

// add this with in your function
$size = File::size($PATH_OF_FILE)

Upvotes: 0

Philipp Palmtag
Philipp Palmtag

Reputation: 1328

You stored your file in the storage folder. You should use the function

storage_path('app/public/'.$picture->filename);

Access to the public folder works only if you used the php artisan storage:link command, to create a symbolic link.

Also

use Illuminate\Support\Facades\Storage;

$size = Storage::size('public/'.$picture->filename');

should work out.

Upvotes: 4

Related Questions