Can anyone please tell me why line 1 works (returns 35434), but line 2 doesn't (returns blank)?
echo $_FILES['userfile']['size'];
die ($_FILES['userfile']['size']);
Thanks!
die
is equivalent to exit
and you'll notice that exit
takes either an integer or a string as an argument. In the case you pass an integer, then the program exits and returns that integer as its exit code.
$_FILES['userfile']['size']
is an integer, not a string, so instead of outputting the message to the screen, it returns the size as the return code of the program.
A simple solution is to concatenate to an empty string to let the PHP compiler you want a string instead of an integer:
die('' . $_FILES['userfile']['size']);
I answered this a few hours ago, anyway the other answers are right.
As a workaround (if you need to do that), casting the integer to a string will do the trick:
die(strval($_FILES['userfile']['size'])); // or
die((string) $_FILES['userfile']['size']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With