note 20880 added to function.filesize
| From: | x at x dot com | Date: | Sat, 20 Apr 2002 00:30:50 +0000 |
| Subject: | note 20880 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-29591@lists.php.net to get a copy of this message | ||
If you want to check the size in order to limit the filesize, this should work.
---------------------------------
function remotefilesize($file)
{
// SETTINGS
$max_file_size = "1000" // in bytes
// Open the file, but only read maximum size
$fp = fopen($file, "r");
$first_file_size_read = fread($fp, $max_file_size);
fclose($fp);
// Open the file plus one byte...
// if there is an extra byte, then it is too big,
$fp = fopen("$image", "r");
$second_file_size_read = fread($fp, $max_file_size + 1);
fclose($fp);
// Check if they're the same
if ($first_file_size_read == $second_file_size_read)
{
$file_size_ok == "yes";
}
}
--------------------------------
What you do with $file_size_ok is up to you after this.
This should work, but it's a dirty hack.
Good luck!
--
http://www.php.net/manual/en/function.filesize.php
http://master.php.net/manage/user-notes.php?action=edit+20880
http://master.php.net/manage/user-notes.php?action=delete+20880
http://master.php.net/manage/user-notes.php?action=reject+20880