note 67040 deleted from function.is-file by bjori
| From: | bjori@php.net | Date: | Fri, 02 Jun 2006 12:27:43 +0000 |
| Subject: | note 67040 deleted from function.is-file by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-112961@lists.php.net to get a copy of this message | ||
Note Submitter: Guilherme Garnier
----
As noticed by amraam at ao dot net, if you have an empty file (0 byte), is_file returns false. But
file_exists returns true.
The following code is a workaround for this problem:
$filename = $argv[1];
if (!file_exists($filename)) {
echo "$filename doesn't exist";
exit;
}
$s = stat($filename);
if ($s === false)
echo "Error";
else
if ($s['size'] == 0)
echo "$filename is an empty file";
else
if (is_file($filename))
echo "$filename is a regular file";
else
echo "$filename is not a file";