note 43900 deleted from function.filesize by aidan
| From: | aidan@php.net | Date: | Thu, 08 Jul 2004 00:31:25 +0000 |
| Subject: | note 43900 deleted from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72845@lists.php.net to get a copy of this message | ||
Note Submitter: tomasz ATNOSPAM codestar DOTNOSPAM se
----
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!