views:

170

answers:

2

hi i am using this exec("du -sh -S ".$fileFlv.""); command in php to get size of a file all the things works fine but the problem at my end is i want only the size but it dispalys the size as well as name of the file

+13  A: 

Have you tried the filesize() function?

Jonas Gulle
+1 - a lot more efficient than spawning a new process!
Paul Dixon
Note: don't forget that php caches the filesize() result.
Zed
+1  A: 

If you just want the size or other properties of a single file, you can use stat instead of du. (There's probably built-in PHP functionality for this too.) The -c option lets you customize the output format. Here's the size in bytes.

stat -c %s myfile.txt

If you really want du (to get total size of directories), you can use cut to munge the output.

du -sh -S mydir | cut -f1

Or just capture the output to a string in PHP and strip the filename there.

Andrew Janke