note 43900 added to function.filesize
| From: | tomaszATNOSPAMcodestarDOTNOSPAMse at rn2 dot php dot net | Date: | Thu, 08 Jul 2004 00:26:56 +0000 |
| Subject: | note 43900 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-72844@lists.php.net to get a copy of this message | ||
I just discovered that filesize ($file) will return the same result throughout the script.
If you for example want to decrease the size of a file until it reaches a certain size you
can't do:...
<?php
while ( filesize ($file) > $maxSize ) {
decreaseFileSizeAndWriteNewFileTo ($file);
}
?>
...as the output of filesize never changes even though the file gets smaller the loop becomes
eternal.
You have to do something like:
<?php
$i = 0;
while ( $i == 0 || filesize ($file . $i) > $maxSize ) {
$i++;
decreaseFileSizeAndWriteNewFileTo ($file . $i);
}
?>
I used this to change the quality of uploaded images until they were small enough for my
requirements. Remember to delete all the junk files this loop will create!
----
Manual Page -- http://www.php.net/manual/en/function.filesize.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43900
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43900&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43900&report=yes
Search -- http://master.php.net/manage/user-notes.php