note 56514 deleted from function.filesize by aidan

From: Date: Wed, 09 Nov 2005 06:14:57 +0000
Subject: note 56514 deleted from function.filesize by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-98301@lists.php.net to get a copy of this message
Note Submitter: flash@houseofzeus ---- A different way to get the filesize using a shell 'hack' (and therefore make your code somewhat platform dependent) is to do the following: <?php $file = "/test/file/location/test.txt"; $filesize = exec("du -h ${file}"); preg_match("/^([0-9\.]+[a-zA-Z]?)[\s]+[.*]/", $filesize, $matches); $filesize = $matches[1]; ?> The regex could probably be cleaner but it does the job. Note that the -h parameter I use here automatically formats the file size. Hence when I run this on an example file the value in $matches[1] is: 7.6M If you just want the raw size in bytes (but without problems when you hit 2 gig etc.) then remove the -h parameter from the exec line.

« previous php.notes (#98301) next »