0

I use the following code to make sure uploaded files are not smaller than or less than a certain size but when someone uploads a file larger than 2GB it triggers PHP to throw of the following error anyway.

'The uploaded file is to small'

What is the best way for me to fix this?

$sizes= filesize($file['tmp_name']);
//File size is less than 40KB so error is threw

if($sizes < 40*1024) {
    $this->setError(JText::_('The uploaded file is to small'));
    return false;
}
C0nw0nk
  • 870
  • 2
  • 13
  • 29
  • See this answer: http://stackoverflow.com/questions/2184513/php-change-the-maximum-upload-file-size – Antony D'Andrea May 15 '15 at 10:40
  • My Upload and Post max file sizes are set to 4000MB that is irrelevant to this topic this is to do with the following. http://php.net/manual/en/function.filesize.php The filesize function will error if the file is larger than 2GB – C0nw0nk May 15 '15 at 10:55
  • Looking at the manual for filesize: Note: Because PHP's integer type is signed and many platforms use 32bit integers, some filesystem functions may return unexpected results for files which are larger than 2GB. – Antony D'Andrea May 15 '15 at 11:00
  • Yes but i cant remove the filesize function since i need to block uploads smaller than 40kb what is the code above. So i need a soloution and i am not sure what options are avaliable. Since if the file upload is larger than 2gb it will show the error "The uploaded file is to small". Since the function can not accurately get the correct size. – C0nw0nk May 15 '15 at 11:18
  • Try this: http://php.net/manual/en/function.filesize.php#112806 here is a function, which can return filesize for files greater than 2 GB in 32 bit OS – pes502 May 15 '15 at 11:38
  • Note that pes502's method pre-supposes that PHP has been compiled with large file support. Although still reliant on LFS, there is a better implementation described here: http://stackoverflow.com/questions/5501451/php-x86-how-to-get-filesize-of-2gb-file-without-external-program – symcbean May 15 '15 at 11:56
  • @symcbean What one of the answers on that topic is best to use since there is none marked and i want that fastest and most efficient method. – C0nw0nk May 15 '15 at 13:05

0 Answers0