note 56514 added to function.filesize

From: Date: Mon, 05 Sep 2005 23:11:55 +0000
Subject: note 56514 added to function.filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-94773@lists.php.net to get a copy of this message
[Self correction of my previous post, if admin could delete the earlier one it would be most appreciated] 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. ---- Manual Page -- http://www.php.net/manual/en/function.filesize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56514 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56514&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56514&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56514&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56514&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56514&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56514&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56514&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94773) next »