Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nhayder's avatar
Level 13

How to get a file size

I'm wondering how to get file sizes for these file formats pdf, imag, mp3, zip, video and maybe for video and audio files is there is a way to get the duration and dimensions ???

Any ideas

0 likes
7 replies
nhayder's avatar
Level 13

@SERGIU17 - thank you, i know about php fileSize() i was wondering if there is a way to do the same in laravel? the filesize php function will not get you the mp3 file duration neither video dimensions

Talinon's avatar

I don't think there is any native way to get that information. You might be able to find some 3rd party package that does this.

One thing you could consider is grabbing the output of a utility such as ffmpeg. You wouldn't need to worry about accounting for all the different audio/video file formats, as it supports many.

Here are a couple threads demonstrating how you might go about it:

https://stackoverflow.com/questions/3069574/get-the-length-of-an-audio-file-php https://superuser.com/questions/650291/how-to-get-video-duration-in-seconds

1 like
Cronix's avatar
Cronix
Best Answer
Level 67

@nhayder You can use FFMpeg to get video lengths, frame dimensions, audio lengths, etc., in addition to being able to convert files between just about any format.

https://github.com/PHP-FFMpeg/PHP-FFMpeg

It's complex, but I don't think you'll find a better tool for the job. It supports about all video/audio codecs so it works on just about anything.

There are laravel wrappers for it as well, but it doesn't do everything the main library can do. https://github.com/pascalbaljetmedia/laravel-ffmpeg

1 like
nhayder's avatar
Level 13

@cronix it looks really complicated :-( there should be an easier way

Cronix's avatar

If you find one, let me know! One of my projects does a heck of a lot of audio/video conversion. I haven't found anything that is nearly as powerful or has all of the needed features and keeps up with newer codecs, which are coming out all of the time. It's definitely a swiss army knife kind of tool. Those are always pretty complicated with lots of options, most of which you'll never use. The actual app is a commandline tool. There are a lot of php (and other language) wrappers for it, but it's a binary under the hood. You could just use exec() and manually use the CLI tool. That's basically all the wrappers are doing.

1 like
nhayder's avatar
Level 13

yah, will update you on this, ...

Please or to participate in this conversation.