Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

>2GB file upload $_FILES["file"]["size"] negative number

Tags:

php

php-5.4

I am getting at >2 GB file upload negative number at $_FILES["file"]["size"].

However file uploads fine and filesize() also returns correct size. But how to solve $_FILES to return correct value?

I have read about the issues at some old versions of php, they also had an error at returning negative number at filesize(), but this seems fine now. Did they just forget to fix $_FILES? Dont you know if its fixed on php 5.5.0 ?

PHP: 5.4.16 OS: Debian Squeeze 6.0.7 x64 Webserver: Nginx 1.2.7

like image 436
Wiggler Jtag Avatar asked Oct 30 '25 06:10

Wiggler Jtag


1 Answers

whatever the problem is, you can probably work around it up to 4GB like this:

$file_size = $_FILES["file"]["size"];
$true_size = $file_size >= 0 ? $file_size : 4*1024*1024*1024 + $file_size;

But, as you said, filesize($_FILES["file"]["tmp_name"]); is the safest way to go (will work above 4GB too).

like image 162
Walter Tross Avatar answered Nov 01 '25 19:11

Walter Tross



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!