note 26515 rejected from function.filesize by nicos

From: Date: Sat, 02 Nov 2002 19:08:46 +0000
Subject: note 26515 rejected from function.filesize by nicos
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-38910@lists.php.net to get a copy of this message
To anyone who has received a 'No such file or directory' error when using 'filesize' or 'filemtime' and you have the appropriate file access permissions, 'fopen' works, and the subject file exists, instead of using: $fname = "/usr/host/path/file.ext"; $fp = @fopen("$fname","r"); if ($fp and file_exists($fname)) { $fsize = intval(filesize($fp) / 1024); } fclose($fp); try: $fname = "/usr/host/path/file.ext"; if (file_exists($fname)) { $farray = stat($fname); $fsize = intval($farray[7] / 1024); // [7] is the index for file size in bytes } I tore my hair out before finding this solution. Cheers.

« previous php.notes (#38910) next »